﻿//using System;
//using System.Collections.Generic;
//using System.ComponentModel;
//using System.Data;
//using System.Drawing;
//using System.Linq;
//using System.Text;
//using System.Windows.Forms;

//namespace ETALON
//{
//    public partial class Form1 : Form
//    {
//        public Form1()
//        {
//            InitializeComponent();
//        }
//    }
//}

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using System.Collections;
using System.IO;
using MySql.Data.MySqlClient;
using System.Data.OleDb;
using h = functionService.shorts;
using da = functionService.DATECOD;
using fr = HK.FiscalRegistrar.FiscalRegistrar;
using vv = functionService.serfun_city7;


namespace ETALON
{
    enum param
    {
        o_l_0 = 0, server_1 = 1, 
        path_to_mdb_2 = 2, 
        default_3 = 3,
        currentMode_CutPaste_4 = 4,
        period_s_5 = 5,
        period_p_6 = 6,
        day_work_7 = 7,
        hasData_s_8 = 8,
        hasData_p_9 = 9,
        raz_pol_10 = 10,
        pass_11=11,
        task_12 = 12,
        listAnyEdit_modeFAED_103 = 103,
        listAnyEdit_cod_104 = 104,
        listAnyEdit_name_105 = 105,
        listAnyEdit_text_106 = 106,
        listAnyEdit_1_146 = 146,
        listAnyEdit_addname_147 = 147,
        listAnyEdit_so_148 = 148,
        zakaz_current_13 = 13,
        treeView_select_14=14,
        zakaz_plase_current_15 = 15,
        path_progr_files_16=16,
        zakaz_kol_17=17,
        zakaz_select_ct_18=18,
        zakaz_td_cod123_19=19,
        sir_current_doc_20=20,
        sir_current_doc_cod123_21=21,
        sir_activTypeDoc_22=22,
        sir_org_23=23,
        sir_tag_rd_24=24,
        editParam_date_25=25,
        sir_nd_26=26,
        sir_org_sf_27=27,
        sir_td_cod123_28=28,
        sir_td_tag_29=29,
        sir_td_tag2_30 = 30,
        sir_path_to_skladMay_31=31,
        size_font_in_GRID_find_32=32,
        zakaz_defaultValue_33=33,
        zakaz_defaultValue_price_34=34,
        tree_position_Width_35 = 35,
        tree_position_Height_36 = 36,
        tree_position_Width_TOV_37 = 37,
        tree_MODE_WAED_38 = 38,
        show_fpa_0InWork_1fiskal_888all_39 = 39,
        fiskalDocAfterPrint_0no_1yes_40=40,
        zakaz_sum_pokup_41=41,
        kafe_smena_42=42,
        kafe_open_smena_43=43,
        kafe_close_smena_44=44,
        zakaz_sum_45=45,
        kassa_sum_smena_46=46,
        select_888All_0vispoln_1fiskal_2predch_20predchVispol_zakaz_47=47,
        name_47__48 = 48,
        type_doc_select_49 = 49,
        pr_tov_inNk2_sklad_50=50,
        pr_tov_inNk2_question_51=51,
        sendData_to_EMAIL_52=52,
        email_adreses_53=53,
        look_mySQL_54=54,
        pass_inServ_55=55,
        prava_adm_56=56,
        name_listtov_57=57,
        name_schema_58=58,
        corg_import_fromSklad_59 = 59,
        bknowCod_60 = 60,
        bProdZeha_61=61
    }
    enum workType { intType, decimalType,
        mony, nameCOD, date, datecod, 
        text, selectOrg,
        selectProdZeh,
        non, selectSirTehn,
        selectKol_siTd,
        selectKol2_sirTd,
        selectPr_sirTd
      }
    enum typeEnterMain { date, date_s_po, server, sotr, no, org_nk, org_sf }
    enum itemTEXT { day, period, has_data, otv_sotr, server}


    public struct SERV  { public static string KIN = "Сервер КИН",EXP = "Сервер Эксп",EMG = "Сервер ЭЛЯ"; }
    public partial class Form1 : Form
    {

        #region  declaration

        FileStream fout;
        StreamWriter fstr_out;
        bool bor;
        functionService.prm_city q; 
        DB_SQL.ConnectionDB_SQL c; 


        //fs.prm_city q;
       // dll_rol.pro_listParam pr;
       // MySqlConnection conn;
       // conn.ConnectionDB cn;
        DataTable tp;
        
        typeEnterMain current_typeEnterMain;
        string[] ai;
        string[] ais;

        const int mc = 6;

        const string MI_DAY = "ДЕНЬ",
                MI_PERIOD = "ПЕРИОД", 
                MI_SOD_DATA = "СОДЕРЖИТ ДАННЫЕ", 
                MI_OTV_L = "ОТВЕТСТВЕННЫЙ",
                MI_ORG_nk = "ОТВЕТСТВЕННЫЙ НК",
                MI_ORG_sf = "ОРГАНИЗАЦИЯ СФ",
                MI_SMENA = "СМЕНА",
                MI_SUMM_CASSA = "СУММА В КАССЕ"; // MI_DOC_PER = "Документы за период"

        DataTable dt_skl_rd;

        #endregion

        public Form1()
        {
            InitializeComponent(); InitializeComponentMy();
            
        }

        #region  ini
        private void InitializeComponentMy()
        {
            setEnabledItem(false);
            tp = new DataTable();
            q = new functionService.prm_city(); 
            toolStripMenuItem63.Text = 
                string.Concat("Активный сервер : ", q.tk(param.server_1));
           
            string[] ai = new string[mc];
            string[] ais = new string[mc];

            //readData_S_PO_InSQLSERVER();
            //setItemsMain();
            dt_skl_rd = new DataTable();
            toolStripMenuItem6.Text = q.tk(param.raz_pol_10);
        }
        void readData_S_PO_InSQLSERVER()
        {
            object op = q.selectScalar(("select Max(dd) as madd from city.sir_rd;"));
            object os = q.selectScalar(("select Min(dd) as midd from city.sir_rd;"));
            q.put(param.hasData_p_9, da.cod_to_date(op));
            q.put(param.hasData_s_8, da.cod_to_date(os));
        }

        private void user_razr(bool IsRazr)
        {
            toolStripMenuItem7.Visible = IsRazr;
            if (IsRazr)
            {
                toolStripMenuItem7.Visible = true;
            }
            else
            {
                toolStripMenuItem7.Visible = false;
            }
        }
        private void cellclick()
        {
             int ic = listView1.SelectedItems.Count;


             if (ic >0)
             {
                 setCurrent();
             }
        }

        #endregion

        #region  functions
        private void workWithFile()
        {

            // Открываем выходной файл,

            fout = new FileStream("t5.xml", FileMode.Create);

            // Записываем в файл алфавит,
            try
            {
                fstr_out = new StreamWriter(fout);
                fstr_out.Write("<t555>");
                fstr_out.Write("<t52211>");
                fstr_out.Write("<t211>");
                fstr_out.Write("t5r4");
                fstr_out.Write("t5r4r");
                fstr_out.Write("</t211>");
                fstr_out.Write("</t52211>");
                fstr_out.Write("</t555>");


                fstr_out.Close();
            }
            catch (IOException exc)
            {
                //   Console.WriteLine(exc.Message + "Ошибка при записи в файл.");fout.Close();
            }
            functionService.shorts.m("OK");

        }
        #endregion

        #region  events
        private void toolStripMenuItem11_Click_1(object sender, EventArgs e)
        {
          //  //t_tov_from_sklad();
          //  string s = "call `city`.`sir_rd_sklad__from__sklad_rd`(8280);"; q.UpdateData(s); h.m(" call ok");
          //  string sql = string.Concat("call `city`.`select_DOC_forADD`();"); DataTable dtt = q.selectAny(sql); q.sh(dtt);
          ////  string sql = string.Concat("select name, sd from city.sir_t_codd;"); DataTable dtt = q.selectAny(sql); q.sh(dtt);
            //prepImport();

            //city7.r444 r = new city7.r444();
            //r.mmm();

           // etr.dic_PLP_v_1 w2 = new etr.dic_PLP_v_1(); w2.mm();

            //city7.plp_enumWithAtributes q1 = new city7.plp_enumWithAtributes(); q1.m1();
           // h.m(city7.readEnum.GetValue_Name_Description(city7.plp_enum.plp.o_l_0));// city7.readEnum.m1();
           // city7.readEnum.G770(city7.plp_enum.plp.o_l_0);
            //city7.readEnum.w22();
        }
        private void toolStripMenuItem6_Click(object sender, EventArgs e)
        {
            string raz_pol_10 = q.tk(param.raz_pol_10);
            string password = "";

            if (raz_pol_10 == city.pro_listselect__user)
            {
                password.pass fp = new password.pass(); fp.ShowDialog(); password = fp.sPassword;
                q.put(param.pass_11, password);
                if (password == "196618") { set_toolStripMenuItem6_text(); }

            }
            else
            {

                set_toolStripMenuItem6_text();
            }
        }
        private void toolStripMenuItem7_Click_1(object sender, EventArgs e)
        {
            listAnyEdit f = new listAnyEdit(
                editParam_SELECT, "city", city.pro_listselect, invert(bor));
            f.ShowDialog();
        }
        private void try1ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string sql_dml = "delete from city.sir_t_codd;"; q.UpdateData(sql_dml);

            sql_dml = "insert into city.sir_t_codd(name, sd, nd) SELECT city.name_cod( concat( s.vd, ' ', s.dd), s.nd) as name, s.dp1 as sd, s.nd as nd FROM sir_rd_sklad s left join sir_rd c on s.nd=c.coddSklad where isnull(coddSklad);";
                         q.UpdateData(sql_dml);

            DataTable d4 = q.selectAny(" select name, sd from city.sir_t_codd;"); 
            
            //q.sh(d4);

        }
        private void toolStripMenuItem9_Click_1(object sender, EventArgs e)
        {
            // dir12(); m(900);
          //  copyDirectoryWithFiles("C:\\work\\donet\\city2");
          //  city7.FormSELtov f = new city7.FormSELtov(); f.ShowDialog();
            enterData.FormED2 f = new enterData.FormED2();
            f.ShowDialog();

        }
        private void toolStripMenuItem2_Click(object sender, EventArgs e)
        {
      

            /* 
             * перед открытием формы запускаем подготовку таблиц:
             * zakaz - перечень объектов с наименованиями, zakaz_folders - перечень и наименование папок в treeView , zakaz_objects - перечень обьектов с адресами папок
             * 
             * из таблиц:
             * zakaz_rd - реквизиты, zakaz_td - товар содержимое
             * 
             */
          

          
        }
        
        private void toolStripMenuItem1_Click_1(object sender, EventArgs e)
        {
          
        }
        private void lookdoc()
        {
            int iso = q.tk_int_codDate_fromDate(param.period_s_5), ipo = q.tk_int_codDate_fromDate(param.period_p_6);
            //h.m(h.az(iso, ipo));
            //"call `city`.`sir_sodDoc_per` (20100901 , 20100920);"
            q.UpdateData(string.Concat( "call `city`.`sir_sodDoc_per` (", iso ," , ", ipo ,");"));
            listAnyEdit ff = new listAnyEdit("city", "sir_rd_doc", true); ff.ShowDialog();
            if (ff.IsOK)
            {
                string scodd = ff.sCod;
                q.put(param.sir_current_doc_20, scodd);
                //678 
                int indexInListView = Convert.ToInt32(scodd.Substring(6, 3)) - 1;

                object odd = q.selectScalar(h.a("select dd from sir_rd where codd = ", scodd, ";"));
                q.put(param.day_work_7, da.cod_to_date(odd));
                listView1.Items.Clear();
                setItemsMain();
                FormDoc d = new FormDoc(indexInListView); d.ShowDialog();
            }
        }
        private void toolStripMenuItem5_Click_2(object sender, EventArgs e)
        {
            FormTREELV f = new FormTREELV("city", "zakaz"); f.ShowDialog();
        }
        private void toolStripMenuItem1_Click(object sender, EventArgs e)
        {

        }
        private void toolStripMenuItem41_Click(object sender, EventArgs e)
        {

        }
        private void listView1_Click(object sender, EventArgs e)
        {
            cellclick();
        }
        private void importFromSkladDecember()
        {

            //C:\work\donet
            //  \\May\\c\\Work\\Sklad\\Skltabl\\Skl4117.mdb
            // \\May\\c\\Work\\Sklad\\Sk4101.mdb
           // q.con.setConn_mdb("C:\\work\\Skl4117.mdb"); q.con.co_mdb();
         //   q.con.setConn_mdb("\\\\May\\c\\Work\\Sklad\\Skltabl\\Skl4117.mdb");

             
           // q.con.setConn_mdb("c:\\Work\\donet\\Skl4117.mdb");
            q.con.setConn_mdb(vv.path_sklad_import);
            q.con.co_mdb();

           

            DataTable rd = q.selectAnyMDB("SELECT nd, dd,vd,corg, dp1,dp2,dp3 FROM  rd where corg=8280 and vd='Нк';"); //q.sh(rd);
            DataTable td = q.selectAnyMDB
                (
                string.Concat
                   (
                        "SELECT t.ndt, t.pp, t.sk, t.ct, t.p2, t.p1, t.mt, t.mnt1, t.mnt2, t.nds, t.crd, t.deb, t.sopp, t.nsk, t.p5t",
                        " FROM td  AS t RIGHT JOIN [SELECT nd FROM  rd where corg=8280 and vd='Нк']. AS r ON t.ndt=r.nd;"
                   )
                );
           // q.sh(td);
            //ct,t,  sk,tsk,up1, tnds, p5t,tt,debt,izm
            DataTable t = q.selectAnyMDB("SELECT ct, t, sk,tsk,up1, tnds, p5t,tt,debt,izm FROM  t;"); //q.sh(t);
            insertToRD(rd);
            insertToTD(td);
            insertToT(t);
           // createTableRDTDdecember();
            prep_SKLAD();
            //m("Выполнено");
        }
        private void importFromSklad()
        {
            
            //  \\May\\c\\Work\\Sklad\\Skltabl\\Skl4117.mdb
            // \\May\\c\\Work\\Sklad\\Sk4101.mdb
            q.con.setConn_mdb(vv.path_sklad_import); q.con.co_mdb();
            DataTable t = q.selectAnyMDB("SELECT ct, t, sk,tsk,up1, tnds, p5t,tt,debt,izm FROM  t;");

            DataTable rd = q.selectAnyMDB("SELECT nd, dd,vd,corg, dp1,dp2,dp3 FROM  rd where corg=166 and vd='Нк';"); //q.sh(rd);
            DataTable td = q.selectAnyMDB
                (
                string.Concat
                   (
                        "SELECT t.ndt, t.pp, t.sk, t.ct, t.p2, t.p1, t.mt, t.mnt1, t.mnt2, t.nds, t.crd, t.deb, t.sopp, t.nsk, t.p5t",
                        " FROM td  AS t RIGHT JOIN [SELECT nd FROM  rd where corg=166 and vd='Нк']. AS r ON t.ndt=r.nd;"
                   )
                );
          //   q.sh(td);
            //ct,t,  sk,tsk,up1, tnds, p5t,tt,debt,izm
             //q.sh(t);

            //собирают данные из файла аксс на сервер в таблицы sklad_rd sklad_td sklad_t
            insertToRD(rd);
            insertToTD(td);
            insertToT(t);
            //----------------------------------------------------------------------------


            prep_SKLAD();
          //  m("Выполнено");
        }
        private void importFromListMDB()
        {
            //cod	name	izm	ves	vih	fpa	codrz
            q.con.setConn_mdb("C:\\work\\donet\\sss.mdb"); q.con.co_mdb();
            DataTable t = q.selectAnyMDB("SELECT cod,name,izm,ves,vih,fpa,codrz FROM sc ;"); q.sh(t);
            insertTo__m2_list_sc(t);
            m("ok");
        }
        private void toolStripMenuItem48_Click(object sender, EventArgs e)
        {
           // m("importFromListMDB()");
            importFromListMDB(); 
        }
        private string nun(object oo)
        {
            if (oo == null) { return "0"; } else { if (oo.ToString().Length > 0) return oo.ToString(); else return "0"; }
        }
        private void insertTo__m2_list_sc(DataTable t)
        {
            // object nd=0, dd=0, vd="", corg=0, dp1=1, dp2=0, dp3=0;
            int ic = t.Rows.Count; string sql_dml = "";
            q.UpdateData("delete from city.m2_list_sc;");
            for (int j = 0; j < ic; j++)
            {

                sql_dml = string.Concat("INSERT INTO city.m2_list_sc(cod,name,izm,ves,vih,fpa,codrz)",
                    " VALUES(",
                    nun(t.Rows[j][0]), ",'",
                    nun(t.Rows[j][1]), "','",
                    nun(t.Rows[j][2]), "',",
                    nun(t.Rows[j][3].ToString().Replace(",",".")), ",",
                    nun(t.Rows[j][4].ToString().Replace(",", ".")), ",",
                    nun(t.Rows[j][5]), ",",
                    nun(t.Rows[j][6]), ");");
                q.UpdateData(sql_dml);
            }

        }
        private void insertToT(DataTable t)
        {
            // object nd=0, dd=0, vd="", corg=0, dp1=1, dp2=0, dp3=0;
            int ic = t.Rows.Count; string sql_dml = "";
            string codMonth_01 = Month01;
            q.UpdateData(string.Concat("delete from citytemp", codMonth_01, ".sklad_t;"));
            for (int j = 0; j < ic; j++)
            {

                sql_dml = string.Concat("INSERT INTO citytemp", codMonth_01 ,".sklad_t(ct,t,  sk,tsk,up1, tnds, p5t,tt,debt,izm)",
                    " VALUES(",
                    nun( t.Rows[j][0]), ",'",
                    nun( t.Rows[j][1]), "',",
                    nun( t.Rows[j][2]), ",'",
                    nun( t.Rows[j][3]), "','",
                    nun( t.Rows[j][4]), "',",
                    nun( t.Rows[j][5]), ",",
                    nun( t.Rows[j][6]), ",",
                   nun(  t.Rows[j][7]), ",",
                   nun( t.Rows[j][8].ToString().Replace(",", ".")), ",",
                   nun(t.Rows[j][9].ToString().Replace(",", ".")), ");");
                q.UpdateData(sql_dml);
            }

        }

        private void insertToRD(DataTable rd)
        {
           // object nd=0, dd=0, vd="", corg=0, dp1=1, dp2=0, dp3=0;
            int ic = rd.Rows.Count; string sql_dml = "";
            string codMonth_01 = Month01;
            q.UpdateData(string.Concat("delete from citytemp", codMonth_01, ".sklad_rd;"));
            for (int j = 0; j < ic; j++)
            {

                sql_dml = string.Concat("INSERT INTO citytemp", codMonth_01, ".sklad_rd(nd, dd,vd,corg, dp1,dp2,dp3)",
                    " VALUES(", 
                    rd.Rows[j][0], ",'",
                   std( rd.Rows[j][1]), "','",
                    rd.Rows[j][2], "',",
                    rd.Rows[j][3], ",'",
                    rd.Rows[j][4], "',",
                    rd.Rows[j][5], ",'",
                    std(rd.Rows[j][6]), "');");
                q.UpdateData(sql_dml);
            }

        }
        private void createTableRDTDdecember()
        {
            q.UpdateData("drop table if exists city.sklad_rdtd;");
            q.UpdateData(
                string.Concat(
                "create table city.sklad_rdtd SELECT nd, date(dd)*1 as dd,vd,corg, t.ct, p2 as pr, mnt1 as k",
                " FROM DATA.sklad_rd r left join DATA.sklad_td t on r.nd=t.ndt",
                " where left(date(dd)*1, 6)*1 =201012 and corg=8280 and vd = 'Нк';")
                );

        }
        private void createTableRDTDany( )
        {
            //int codMonth201101
            string codMonth_01 = Month01; string codMonth201101 = string.Concat(Year2011, codMonth_01);
            q.UpdateData(string.Concat("drop table if exists citytemp", codMonth_01, ".sklad_rdtd;"));
            q.UpdateData(
                string.Concat(
                "create table citytemp", codMonth_01, ".sklad_rdtd SELECT nd, date(dd)*1 as dd,vd,corg, t.ct, p2 as pr, mnt1 as k",
                " FROM citytemp", codMonth_01, ".sklad_rd r left join citytemp", codMonth_01, ".sklad_td t on r.nd=t.ndt",
                " where left(date(dd)*1, 6)*1 =", codMonth201101, " and corg=166 and vd = 'Нк';")
                );

        }

        private string std(object s2011_03_03__010101)
        {
            string s = s2011_03_03__010101.ToString(); string sd; 
            //sd = string.Concat( s.ToString().Substring(0,2), ".",
            //    s.ToString().Substring(3, 2), ".", s.ToString().Substring(6, 4));
            sd = string.Concat(s.ToString().Substring(6, 4), ".",
                s.ToString().Substring(3, 2), ".", s.ToString().Substring(0, 2));
            return sd;
        }

        private void insertToTD(DataTable td)
        {
            // object nd=0, dd=0, vd="", corg=0, dp1=1, dp2=0, dp3=0;
            int ic = td.Rows.Count; string sql_dml = "";
            q.UpdateData(string.Concat("delete from citytemp",Month01 ,".sklad_td;"));
            for (int j = 0; j < ic; j++)
            {
                sql_dml = string.Concat("INSERT INTO citytemp", Month01, ".sklad_td(ndt,pp,sk,ct,p2,p1,mt,mnt1,mnt2,nds,crd,deb,sopp,nsk,p5t)",
                    " VALUES(", nun(td.Rows[j][0].ToString().Replace(",", ".")), ",", 
                    nun(td.Rows[j][1].ToString().Replace(",", ".")), ",",
                    nun(td.Rows[j][2].ToString().Replace(",", ".")), ",", 
                     nun(td.Rows[j][3].ToString().Replace(",", ".")), ",",
                     nun(td.Rows[j][4].ToString().Replace(",", ".")), ",",
                     nun(td.Rows[j][5].ToString().Replace(",", ".")), ",",
                     nun(td.Rows[j][6].ToString().Replace(",", ".")), ",",
                     nun(td.Rows[j][7].ToString().Replace(",", ".")), ",",
                     nun(td.Rows[j][8].ToString().Replace(",", ".")), ",",
                     nun(td.Rows[j][9].ToString().Replace(",", ".")), ",",
                     nun(td.Rows[j][10].ToString().Replace(",", ".")), ",",
                     nun(td.Rows[j][11].ToString().Replace(",", ".")), ",",
                     nun(td.Rows[j][12].ToString().Replace(",", ".")), ",",
                     nun(td.Rows[j][13].ToString().Replace(",", ".")), ",",
                     nun(td.Rows[j][14].ToString().Replace(",", ".")), ");"); 
                    
                
                     //td.Rows[j][0] ,",",
                     //td.Rows[j][1] ,",", 
                     //td.Rows[j][2] ,",", 

                     //td.Rows[j][3] ,",", 
                     //td.Rows[j][4].ToString().Replace(",",".") ,",",
                     //td.Rows[j][5].ToString().Replace(",", "."), ",", 
                     //td.Rows[j][6] ,",", 
                     //td.Rows[j][7] ,",", 
                     //td.Rows[j][8] ,",", 
                     //td.Rows[j][9] ,",",
                     //td.Rows[j][10].ToString().Replace(",", "."), ",",
                     //td.Rows[j][11].ToString().Replace(",", "."), ",", 
                     //td.Rows[j][12] ,",", 
                     //td.Rows[j][13] ,",", 
                     //td.Rows[j][14] ,");");
                q.UpdateData(sql_dml);
            }

        }

        private void  insert_to_list_sc(object cod, object name)
        {
            string sql_dml = string.Concat("INSERT INTO list_sc(cod, name) VALUES (", cod, ",'", name, "'); "); q.UpdateData(sql_dml);
        }
        private void handAddListTov_to_sirList()
        {
            DataTable ttov = q.selectAny("SELECT cod, name FROM listtov;");
            DataTable tsir = q.selectAny("SELECT cod, name FROM list_sc;");

            object om = tsir.Compute("max(cod)", "cod>0"); int im = Convert.ToInt32(om);
            DataRow r;
            for (int i = 0; i < ttov.Rows.Count; i++)
            {
                im++; r = tsir.NewRow(); r[0] = im; r[1] = ttov.Rows[i][1]; tsir.Rows.Add(r);
            }
            tsir.AcceptChanges();

            string sql_dml = "delete from list_sc;"; q.UpdateData(sql_dml);

            foreach (DataRow rr in tsir.Rows){ insert_to_list_sc(rr[0],rr[1]); }
            h.m("Выполнено");
        }
        public class ppp
        {
            private DateTime dt;
            private int ee;
            private string ss, sss;
            w2 w22;
            string[] s11 = new string[] { "y6", "u7", "u7u7", "i88", "i8" };
            ArrayList y6;

            public ppp()
            {
                y6 = new ArrayList(); y6.Add("o9o9"); y6.Add("o9i8");
            }

            [Category("1. Идентификация")]
            [DisplayName("ТАКОЙ ArrayList")]
            public ArrayList arr
            {
                get { return y6; }
                set { y6 = value; }
            }

           public  enum w2 { r4,t5,y6,u7}
           [Category("1. Идентификация")]
           [DisplayName("МАССИВ СТРОК")]
           public string[] q111
           {
               get { return s11; }
               set { s11 = value; }
           }
           [Category("1. Идентификация")]
           [DisplayName("ОПРО")]
           public w2 tttt
           {
               get { return w22; }
               set { w22 = value; }
           }
           [Category("1. Идентификация")]
           [DisplayName("Номер")]
            public int nnn
            {
              get
              {
                  return ee;
              }
                set { ee = value; }
            }
            [Category("2. Другое")]
            [DisplayName("Заголовок")]
            public string rrr
            {
                get { return ss; }
                set { ss = value; }
            }
            [Category("2. Другое")]
            [DisplayName("Другое")]
             public string ttt
            {
                get { return sss; }
                set { sss = value; }
            }
        }

        private void toolStripMenuItem49_Click(object sender, EventArgs e)
        {
            //////////FormM f = new FormM(); f.ShowDialog();
            //////ppp r = new ppp(); r.nnn  = 2020; r.ttt    = "y6y6"; r.rrr   = "e3e3";
            //////city7.FormPropertyGrid f = new city7.FormPropertyGrid();
            ////////fp.propert
            //////f.propertyGrid1.Font = new Font( "Tahoma", 14);
            //////f.propertyGrid1.SelectedObject = r;
            //////f.ShowDialog();

            string s = q.tk(param.period_s_5); DateTime dmy = Convert.ToDateTime(s) ;
            h.m(SMENA.Substring(1, 2)," ", 
               Month01 ," ", dmy.Year);


        }
        private void toolStripMenuItem50_Click(object sender, EventArgs e)
        {

            //listAnyEdit f = new listAnyEdit(deleg000, "city", city.listtov, invert(bor));
            //f.ShowDialog();


        }
        private void toolStripMenuItem6_Click_1(object sender, EventArgs e)
        {
            workWithFile();
        }
        private void toolStripMenuItem7_Click(object sender, EventArgs e)
        {
            DataTable dt =  q.selectAny("SELECT codMLU, g1f,g1i,g1o FROM zarpl.llcwork l;"); q.sh(dt);
        }
        private void toolStripComboBox2_TextChanged(object sender, EventArgs e)
        {

            ////pr.put(1, toolStripComboBox2.Text);
            ////toolStripStatusLabel1.Text = toolStripComboBox2.Text;
            ////Application.Exit();
        }
        private void toolStripMenuItem5_Click(object sender, EventArgs e)
        {


        }
        private void toolStripMenuItem8_Click(object sender, EventArgs e)
        {
             DataTable t = q.selectAny("SELECT * FROM nachislenie_history_2009_43 n;"); 
            string l = " ";
            functionService.shorts.m(
                string.Concat(t.Rows[0][4], l, t.Rows[0][5], l, t.Rows[0][6], l, t.Rows[0][7], l, t.Rows[0][8], l, t.Rows[0]["nch"])
                );
        }
        private void toolStripMenuItem5_Click_1(object sender, EventArgs e)
        {
            //cn.cnn.Open();
            //DataTable dt = selectAnyMDB("select * from llc");
            //sh(dt);
            //cn.cnn.Close();
        }
        private void toolStripMenuItem3_Click(object sender, EventArgs e)
        {


            //tp.Clear();
            //tp = q.pr.pro_listParam_read; ;
            //q.sh(tp);
            //q.pr.pro_listParam_save();
        }
        private void toolStripMenuItem9_Click(object sender, EventArgs e)
        {
            //conn.Open(); 
            //fs.shorts.m(selectScalar("select count(*) from llcwork;"));
            //conn.Close();
        }
        private void toolStripMenuItem10_Click(object sender, EventArgs e)
        {
            //cn.cnn.Open();
            //fs.shorts.m(selectScalarMDB("select count(*) from llc;"));
            //cn.cnn.Close();
        }
        private void toolStripMenuItem11_Click(object sender, EventArgs e)
        {
            q.UpdateData("drop table if exists llcwork_copy;");
            q.UpdateData("create table llcwork_copy select * from llcwork;");
            q.UpdateData("delete from llcwork_copy where codMLU<1;");
            functionService.shorts.m("ok"); 
        }
        private void toolStripMenuItem13_Click(object sender, EventArgs e)
        {
            //  FormTREE f = new FormTREE("tables"); f.ShowDialog();
        }
        private void toolStripMenuItem14_Click(object sender, EventArgs e)
        {

            //fs.prm_city q = new SERVICE();
            string[] af = Directory.GetFiles("G:\\1");
            DataTable t = new DataTable();
            t.Columns.Add("cod123", typeof(int)); t.Columns.Add("name", typeof(string)); t.AcceptChanges();
            t.Columns[0].AutoIncrement = true; t.Columns[0].AutoIncrementSeed = 1; t.Columns[0].AutoIncrementStep = 1;


            DataRow r;
            for (int i = 0; i < af.Length; i++)
            {
                r = t.NewRow(); r[1] = functionService.shorts.read(af[i], 25); t.Rows.Add(r);
            }
            t.AcceptChanges();
            DataView v = new DataView(t); v.Sort = "name"; //q.sh(v);
            for (int i = 0; i < v.Count; i++)
            {
                File.Copy(string.Concat("G:\\1\\", v[i][1]), string.Concat("G:\\2\\", v[i][1]));
            }
            functionService.shorts.m("ok");
        }
        private void toolStripMenuItem15_Click(object sender, EventArgs e)
        {
            WORK.FormTXT f = new WORK.FormTXT(); f.ShowDialog();

        }
        private void toolStripMenuItem16_Click(object sender, EventArgs e)
        {
            //  FormTREE f = new FormTREE("sotr"); f.ShowDialog();
        }
        private void toolStripMenuItem17_Click(object sender, EventArgs e)
        {
            //  FormTREE f = new FormTREE("zak"); f.ShowDialog();
        }
        private void toolStripDropDownButton7_Click(object sender, EventArgs e)
        {

        }
        private void toolStripMenuItem33_Click(object sender, EventArgs e)
        {
            //ETALON.tree.FormPROD f = new ETALON.tree.FormPROD(); f.ShowDialog();
        }
        private void toolStripMenuItem40_Click(object sender, EventArgs e)
        {
            //DataTable dt = q.pr.pro_listParam_read;
            //q.sh(dt);
            //q.pr.pro_listParam_save();
            ETALON.FormCreateFileParam f = new ETALON.FormCreateFileParam(); f.ShowDialog();
        }
        private void toolStripMenuItem45_Click(object sender, EventArgs e)
        {

        }
        private void toolStripMenuItem32_Click(object sender, EventArgs e)
        {
            
        }
        private void toolStripMenuItem42_Click(object sender, EventArgs e)
        {
            
        }
        private void toolStripMenuItem34_Click(object sender, EventArgs e)
        {
        }
        private void toolStripMenuItem38_Click(object sender, EventArgs e)
        {
        }
        #endregion

        #region  servis fun
        //private void setConn()
        //{
        //    string ss = pr.take(1);
        //    if (ss == SERV.KIN)
        //    {
        //        conn = new MySqlConnection("server=localhost;user id=muser; password=; database=city; pooling=false");
        //    }
        //    else if (ss == SERV.EXP)
        //    {
        //        conn = new MySqlConnection("server=serverExp;user id=muser; password=; database=city; pooling=false");
        //    }
        //    else if (ss == SERV.EMG)
        //    {
        //        conn = new MySqlConnection("server=Homekin;user id=muser; password=; database=city; pooling=false");
        //    }
        //    toolStripStatusLabel1.Text = ss;

        //    cn = new conn.ConnectionDB(tk(param.path_to_mdb_2));
        //}
        //public void UpdateData(string strSQL_DML)
        //{
        //    MySqlCommand cmd = conn.CreateCommand(); cmd.CommandText = strSQL_DML; cmd.ExecuteNonQuery();
        //}
        
        //public void UpdateDataMDB(string strSQL_DML)
        //{
        //    // MySqlCommand cmd = conn.CreateCommand(); cmd.CommandText = strSQL_DML; cmd.ExecuteNonQuery();
        //    OleDbCommand cmd = cn.cnn.CreateCommand(); cmd.CommandText = strSQL_DML; cmd.ExecuteNonQuery();
        //}
        //public object selectScalar(string strSQL_SCALAR)
        //{
        //    MySqlCommand cmd = conn.CreateCommand();
        //    cmd.CommandText = strSQL_SCALAR;
        //    object o = cmd.ExecuteScalar(); return o;
        //}
        //public object selectScalarMDB(string strSQL_SCALAR)
        //{
        //    // MySqlCommand cmd = conn.CreateCommand(); cmd.CommandText = strSQL_DML; cmd.ExecuteNonQuery();
        //    OleDbCommand cmd = cn.cnn.CreateCommand();
        //    cmd.CommandText = strSQL_SCALAR; object o = cmd.ExecuteScalar(); return o;
        //}
        //private void m(object o)
        //{
        //    MessageBox.Show(o.ToString());

        //}

        //private void sh(DataTable d)
        //{
        //    grid.FormGRID f = new grid.FormGRID(d); f.ShowDialog();
        //}
        //private void sh(DataView v)
        //{
        //    grid.FormGRID f = new grid.FormGRID(v); f.ShowDialog();
        //}
        //private string tk(param pro)
        //{
        //    return pr.take((int)pro);
        //}

        //public DataTable selectAny(string sSQL)
        //{
        //    DataTable dt = new DataTable();
        //    try
        //    {
        //        MySqlCommand c = new MySqlCommand(sSQL); MySqlDataReader rd; c.Connection = conn;
        //        rd = c.ExecuteReader();
        //        dt.Load(rd, LoadOption.OverwriteChanges);
        //    }
        //    catch (Exception e) { m(e.Message); }
        //    return dt;

        //}
        //public DataTable selectAnyMDB(string sSQL)
        //{
        //    DataTable dt = new DataTable();
        //    try
        //    {
        //        OleDbCommand c = new OleDbCommand(sSQL);
        //        OleDbDataReader rd;
        //        c.Connection = cn.cnn ;
        //                rd = c.ExecuteReader();
        //        dt.Load(rd, LoadOption.OverwriteChanges);
        //    }
        //    catch (Exception e) { m(e.Message); }
        //    return dt;

        //}
        #endregion
        private void openListPlaces()
        {
            q.put(param.default_3, "Стол"); string s = q.tk(param.default_3);
            FormTREELV f = new FormTREELV("city", city.listtable); f.ShowDialog();
        }
        private void openListSotr()
        {
            MessageBox.Show("u7");
        }
        private void m(object oo)
        {
            MessageBox.Show(oo.ToString());
        }
        public bool invert(bool tr)
        {
            if (tr == true)
            {
                return false;
            }
            else
            {
                return true;
            }
        }

        private void openListProd()
        {
            functionService.prm_city q = new functionService.prm_city();
            string sql = string.Concat("call `city`.`create_objects_IfNewCodObject`('listtov');");
            
            q.con.setConn(q.tk(param.server_1));            //q.setConn("city");q.co();
            q.con.pass =  q.tk(param.pass_inServ_55); q.con.co(q.tk(param.server_1));
            q.UpdateData(sql); q.put(param.default_3, "Продукция");
            FormTREELV f = new FormTREELV("city", "listtov"); f.ShowDialog();
        }
        private void openListSirTehnolog()
        {
            functionService.prm_city q = new functionService.prm_city();
            string sql = string.Concat("call `city`.`create_objects_IfNewCodObject`('sir_listsir');");

            q.con.setConn(q.tk(param.server_1));            //q.setConn("city");q.co();
            q.con.pass =  q.tk(param.pass_inServ_55); q.con.co(q.tk(param.server_1));
            q.UpdateData(sql); q.put(param.default_3, "Сырье");
            FormTREELV f = new FormTREELV("city", "sir_listsir"); f.ShowDialog();
        }
        private string OTV_L
        {
            get
            {
                string s = vv.o_l_0;// q.tk(param.o_l_0); 
                return s;
            }
        }
        
        private string MI_ORG_nk_L
        {
            get
            {
                string s = q.tk(param.sir_org_23); return s;
            }
        }
        public  string MI_SUMMA_CASSA_L
        {
            get
            {
                string s = "0";
                if (q.tk((int)param.look_mySQL_54) == "1")
                {
                    string kafe_smena_42_11214 = q.tk((int)param.kafe_smena_42);
                    string sql_count = string.Concat("select count(codd) as cc from city.zakaz_rd where Left(codd,5) = ", kafe_smena_42_11214, ";");
                    string sql_skalar = string.Concat("SELECT sum(kol*pr) as sumKassa FROM zakaz_td z left join zakaz_rd r on z.codd = r.codd where (r.fpa = 1 and (Left(z.codd,5) = ", kafe_smena_42_11214, ")) group by Left(z.codd,5) order by z.codd;");
                    object oc = q.selectScalar(sql_count);
                    object os = 0; 
                    if (Convert.ToInt32(oc) > 0) { os = q.selectScalar(sql_skalar); }
                    try { s = os.ToString(); }
                    catch { s = "0"; }
                }
                return s;
            }
        }
        private string MI_ORG_sf_L
        {
            get
            {
                string s = q.tk(param.sir_org_sf_27); return s;
            }
        }
        private string MI_DOC_PER_L
        {
            get
            {
                string s = ""; 
                return s;
            }
        }
        private string SERVER_select
        {
            get
            {
                string s = q.tk(param.server_1); return s;
            }
        }
        private string DAY
        {
            get 
            {
                string s = q.tk(param.day_work_7); return s;
            }
        }
        private string  Month01
        {
            get
            {
                string s = q.tk(param.period_s_5);
                DateTime dmy = Convert.ToDateTime(s); return h.nn( dmy.Month);
            }
        }
        private int Year2011
        {
            get
            {
                string s = q.tk(param.period_s_5); DateTime dmy = Convert.ToDateTime(s);
                return dmy.Year;
            }
        }
        private string SMENA
        {
            get
            {
                string s = da.codDATE_10913_from_codDATE_20100913( da.date_to_cod_str ( q.tk(param.day_work_7))).ToString(); return s;
            }
        }
        private string period_s_p
        {
            get
            {
                string s = q.tk(param.period_s_5);
                string p = q.tk(param.period_p_6);
                
                return string.Concat("С  ", s ,"  ПО  ", p);
            }
        }
        private string hasData_s_p
        {
            get
            {
                string s = q.tk(param.hasData_s_8);
                string p = q.tk(param.hasData_p_9);

                return string.Concat("С  ", s, "  ПО  ", p);
            }
        }
        private void setCurrent()
        {
            ListViewItem ci = listView1.SelectedItems[0]; string sw = ci.Text; int ii = listView1.SelectedItems[0].Index;
            string sd="";

            switch (sw)
            {
                case MI_DAY :
                   
                        LT.FormDate fd = new LT.FormDate(); fd.ShowDialog();
                        if (fd.bOk == true)
                        {
                            sd = fd.dateSelect.ToShortDateString();
                            q.put(param.day_work_7, sd);
                            q.put(param.period_s_5, sd);
                            q.put(param.period_p_6, sd);
                        }
                        ci.SubItems[1].Text = DAY;
                        q.put((int)param.kafe_smena_42, SMENA);
                        listView1.Items[ii + 1].SubItems[1].Text = SMENA;
                        listView1.Items[ii + 5].SubItems[1].Text = MI_SUMMA_CASSA_L ;
                        listView1.Items[ii + 2].SubItems[1].Text = period_s_p;
                    
                    break;
                case MI_PERIOD :

                    FormDATEspo f = new FormDATEspo(q.tk(param.period_s_5).Replace("0001", "2011"), q.tk(param.period_p_6).Replace("0001", "2011"));
                        f.ShowDialog();
                        if (f.bOks == true) q.put(param.period_s_5, f.dateSelectS.ToShortDateString());
                        if (f.bOkp == true) q.put(param.period_p_6, f.dateSelectP.ToShortDateString());
                        ci.SubItems[1].Text = period_s_p;
                    
                    break;
                case MI_SOD_DATA :
                  
                        lookdoc();//h.m("100");
                    
                    break;
                case MI_OTV_L :
                    
                        listAnyEdit fa = new listAnyEdit("lists", city.sotr, true);
                        fa.ShowDialog();
                        if (fa.IsOK) 
                        {
                            q.put(param.o_l_0, fa.sText); vv.o_l_0 = fa.sText;
 
                            ci.SubItems[1].Text = fa.sText; 
                        }
                     
                    break;
                case MI_ORG_nk:
                    
                        listAnyEdit faa = new listAnyEdit("city", "sir_listorg", true);
                        faa.ShowDialog();
                        if (faa.IsOK) { q.put(param.sir_org_23, faa.sText); ci.SubItems[1].Text = faa.sText; }
                    
                    break;
                case MI_ORG_sf:
                    
                        listAnyEdit faaa = new listAnyEdit("lists", "org_listorg", true);
                        faaa.ShowDialog();
                        if (faaa.IsOK) { q.put(param.sir_org_sf_27, faaa.sText); ci.SubItems[1].Text = faaa.sText; }
                    
                    break;
               
            }
            
        }
        private void setItemsMain()
        {

            ListViewItem[] av = new ListViewItem[mc]; Font font_main = new Font("Courier New", 24);

            ai = new string[mc] 
            {
                MI_DAY,
                MI_SMENA,
                MI_PERIOD,
                MI_SOD_DATA ,
                MI_OTV_L,
                MI_SUMM_CASSA 
                //MI_ORG_nk , 
                //MI_ORG_sf 
            };
             ais = new string[mc] 
            {
                DAY,
                SMENA,
                period_s_p,
                hasData_s_p,
                OTV_L,
                MI_SUMMA_CASSA_L
                // MI_ORG_nk_L , MI_ORG_sf_L  
            }; 
            for (int i = 0; i < mc; i++) { av[i] = new ListViewItem(ai[i]); av[i].Font = font_main; av[i].SubItems.Add(ais[i]); }

            av[0].SubItems[1].Tag = typeEnterMain.date;
            av[1].SubItems[1].Tag = typeEnterMain.no;
            av[2].SubItems[1].Tag = typeEnterMain.date_s_po;
            av[3].SubItems[1].Tag = typeEnterMain.no;
            av[4].SubItems[1].Tag = typeEnterMain.no;
            av[5].SubItems[1].Tag = typeEnterMain.no  ;
            //av[6].SubItems[1].Tag = typeEnterMain.org_sf;
            

            av[0].ImageIndex = 14;
            av[1].ImageIndex = 13;
            av[2].ImageIndex = 11;
            av[3].ImageIndex = 11;
            av[4].ImageIndex = 13;
            av[5].ImageIndex = 18;
            //av[6].ImageIndex = 13;
            

            listView1.View = View.Details;
            for (int i = 0; i < mc; i++) { listView1.Items.Add(av[i]); }

            toolStripMenuItem30.Text = string.Concat("Открытая смены :", q.tk((int)param.kafe_open_smena_43));
            toolStripMenuItem42.Text = string.Concat("Закрытая смена :", q.tk((int)param.kafe_close_smena_44));
        }
        
        #region edit param
        private void editParam_tehsir(object ocodo)
        {

            string sql = string.Concat("SELECT * FROM city.list_tehsir_z where cod = ", ocodo, ";");
            DataTable dt = q.selectAny(sql);


            ListViewItem[] viTOV = new ListViewItem[3];

            viTOV[0] = new ListViewItem("Наименование (код)");
            viTOV[1] = new ListViewItem("ЕдИзм");
            viTOV[2] = new ListViewItem("ЕдПреобр");

            viTOV[0].ImageIndex = 5;
            viTOV[1].ImageIndex = 6;
            viTOV[2].ImageIndex = 6;
            // m(45);
            viTOV[0].Tag = string.Concat((int)workType.nameCOD, "; name_cod");
            viTOV[1].Tag = string.Concat((int)workType.text, "; izm");
            viTOV[2].Tag = string.Concat((int)workType.text, "; ep");


            viTOV[0].SubItems.Add(functionService.nameCod.name_cod(dt.Rows[0]["name"], dt.Rows[0]["cod"]));
            viTOV[1].SubItems.Add(dt.Rows[0]["izm"].ToString());
            viTOV[2].SubItems.Add(dt.Rows[0]["ep"].ToString());
            // m(46);
            viTOV[0].Font = new Font("Tahoma", 24);
            viTOV[1].Font = new Font("Tahoma", 24);
            viTOV[2].Font = new Font("Tahoma", 24);
            // m(5);

            FormListParam f = new FormListParam(viTOV); f.ShowDialog();
            //m(55);

            if (f.IsOk)
            {
                viTOV[1].SubItems[1].Text = (f.listView1.Items[1].SubItems[1].Text);
                viTOV[2].SubItems[1].Text = (f.listView1.Items[2].SubItems[1].Text);

                string sql_Update = string.Concat("UPDATE city.list_tehsir_z SET izm = '",
                    viTOV[1].SubItems[1].Text,
                    "', ep = ", viTOV[2].SubItems[1].Text.Replace(",","."), " WHERE cod = ", ocodo);
                // h.m(sql_Update);
                q.UpdateData(sql_Update);
                // h.m(20);
            }

        }

        private void editParam_sht_zeh(object ocodo)
        {
            string sql = string.Concat("SELECT cod, name, izm, ves FROM list_sc l where cod = ", ocodo, ";");
            DataTable dt = q.selectAny(sql);

            ListViewItem[] viTOV = new ListViewItem[3];

            viTOV[0] = new ListViewItem("Наименование (код)");
            viTOV[1] = new ListViewItem("ЕдИзм");// "Ед Изм"; 
            viTOV[2] = new ListViewItem("вес");

            viTOV[0].ImageIndex = 5;
            viTOV[1].ImageIndex = 6;
            viTOV[2].ImageIndex = 6;

            viTOV[0].Tag = string.Concat((int)workType.nameCOD, "; name_cod");
            viTOV[1].Tag = string.Concat((int)workType.text, "; izm");
            viTOV[2].Tag = string.Concat((int)workType.text, "; ves");
            
            viTOV[0].SubItems.Add(functionService.nameCod.name_cod(dt.Rows[0]["name"], dt.Rows[0]["cod"]));
            viTOV[1].SubItems.Add(dt.Rows[0]["izm"].ToString());
            viTOV[2].SubItems.Add(dt.Rows[0]["ves"].ToString());
       
            viTOV[0].Font = new Font("Tahoma", 24);
            viTOV[1].Font = new Font("Tahoma", 24);
            viTOV[2].Font = new Font("Tahoma", 24);

            FormListParam f = new FormListParam(viTOV); f.ShowDialog();

            for (int j = 0; j < 3; j++)
            {
                viTOV[j].SubItems[1].Text = f.listView1.Items[j].SubItems[1].Text;
            }

            string sql_Update = string.Concat("UPDATE city.list_sc SET izm = '",
                viTOV[1].SubItems[1].Text, "', ves = ", viTOV[2].SubItems[1].Text.Replace(",","."), " WHERE cod = ", ocodo, ";");
            //conn.Open();
            q.UpdateData(sql_Update);

        }


        private void editParam_pr(object ocodo)
        {
            string sql = string.Concat("SELECT * FROM listtov l where cod = ", ocodo , ";");
            DataTable dt = q.selectAny(sql);
            
            ListViewItem[] viTOV = new ListViewItem[6];

            viTOV[0] = new ListViewItem("Наименование (код)");
            viTOV[1] = new ListViewItem("Цена0 Приход");// "Цена0 Приход"; 
            viTOV[2] = new ListViewItem("Цена1 Продажи");// "Цена1 Продаж"; 
            viTOV[3] = new ListViewItem("Цена2 Скидка");// "Цена2 "; 
            viTOV[4] = new ListViewItem("Цена3");// "Цена3 "; 
            viTOV[5] = new ListViewItem("Цена4");// "Цена3 "; 

            viTOV[0].ImageIndex = 5;
            viTOV[1].ImageIndex = 6;
            viTOV[2].ImageIndex = 6;
            viTOV[3].ImageIndex = 6;
            viTOV[4].ImageIndex = 6;
            viTOV[5].ImageIndex = 6;

            viTOV[0].Tag = string.Concat((int)workType.nameCOD, "; name_cod");
            viTOV[1].Tag = string.Concat((int)workType.mony, "; pr1");
            viTOV[2].Tag = string.Concat((int)workType.mony, "; pr2");
            viTOV[3].Tag = string.Concat((int)workType.mony, "; pr3");
            viTOV[4].Tag = string.Concat((int)workType.mony, "; pr4");
            viTOV[5].Tag = string.Concat((int)workType.mony, "; pr5");

            viTOV[0].SubItems.Add(functionService.nameCod.name_cod(dt.Rows[0]["name"], dt.Rows[0]["cod"]));
            viTOV[1].SubItems.Add(dt.Rows[0]["pr1"].ToString());
            viTOV[2].SubItems.Add(dt.Rows[0]["pr2"].ToString());
            viTOV[3].SubItems.Add(dt.Rows[0]["pr3"].ToString());
            viTOV[4].SubItems.Add(dt.Rows[0]["pr4"].ToString());
            viTOV[5].SubItems.Add(dt.Rows[0]["pr5"].ToString());

            viTOV[0].Font = new Font("Tahoma", 24);
            viTOV[1].Font = new Font("Tahoma", 24);
            viTOV[2].Font = new Font("Tahoma", 24);
            viTOV[3].Font = new Font("Tahoma", 24);
            viTOV[4].Font = new Font("Tahoma", 24);
            viTOV[5].Font = new Font("Tahoma", 24);



            FormListParam f = new FormListParam(viTOV); f.ShowDialog();

            for (int j = 0; j < 6; j++)
            {
                viTOV[j].SubItems[1].Text = f.listView1.Items[j].SubItems[1].Text;
            }

            string sql_Update = string.Concat("UPDATE city.listtov SET pr1 = ",
                viTOV[1].SubItems[1].Text.Replace(',', '.'), ", pr2=",
                viTOV[2].SubItems[1].Text.Replace(',', '.'), ", pr3=",
                viTOV[3].SubItems[1].Text.Replace(',', '.'), ", pr4=",
                viTOV[4].SubItems[1].Text.Replace(',', '.'), ", pr5=",
                viTOV[5].SubItems[1].Text.Replace(',', '.'), " WHERE cod = ", ocodo);
            //conn.Open();
            q.UpdateData(sql_Update);
            
        }
        
        private void editParam_sotr(object ocodo)
        {
            string sql = string.Concat("SELECT * FROM lists.sot_listsot l where cod = ", ocodo, ";");
            DataTable dt = q.selectAny(sql);

            ListViewItem[] viTOV = new ListViewItem[2];

            viTOV[0] = new ListViewItem("Наименование (код)");
            viTOV[1] = new ListViewItem("PASS");// "Цена0 Приход"; 
           
            viTOV[0].ImageIndex = 5;
            viTOV[1].ImageIndex = 6;
            
            viTOV[0].Tag = string.Concat((int)workType.nameCOD, "; name_cod");
            viTOV[1].Tag = string.Concat((int)workType.mony, "; pr1");
           
            viTOV[0].SubItems.Add(functionService.nameCod.name_cod(dt.Rows[0]["name"], dt.Rows[0]["cod"]));
            viTOV[1].SubItems.Add(dt.Rows[0]["pass"].ToString());
           
            viTOV[0].Font = new Font("Tahoma", 24);
            viTOV[1].Font = new Font("Tahoma", 24);
            
            FormListParam f = new FormListParam(viTOV); f.ShowDialog();

            for (int j = 0; j < 2; j++)
            {
                viTOV[j].SubItems[1].Text = f.listView1.Items[j].SubItems[1].Text;
            }

            string sql_Update = string.Concat("UPDATE lists.sot_listsot SET pass = ",
                viTOV[1].SubItems[1].Text.Replace(',', '.'),
                " WHERE cod = ", ocodo);
            q.UpdateData(sql_Update);

            
        }

        private void editParam_SIR_sc(object ocodo)
        {

            string sql = string.Concat("SELECT * FROM city.list_sc where cod = ", ocodo, ";");
            DataTable dt = q.selectAny(sql);


            ListViewItem[] viTOV = new ListViewItem[2];

            viTOV[0] = new ListViewItem("Наименование (код)");
            viTOV[1] = new ListViewItem("ЕдИзм");// "Цена0 Приход"; 


            viTOV[0].ImageIndex = 5;
            viTOV[1].ImageIndex = 6;
            // m(45);
            viTOV[0].Tag = string.Concat((int)workType.nameCOD, "; name_cod");
            viTOV[1].Tag = string.Concat((int)workType.text, "; izm");


            viTOV[0].SubItems.Add(functionService.nameCod.name_cod(dt.Rows[0]["name"], dt.Rows[0]["cod"]));
            viTOV[1].SubItems.Add(dt.Rows[0]["izm"].ToString());
            // m(46);
            viTOV[0].Font = new Font("Tahoma", 24);
            viTOV[1].Font = new Font("Tahoma", 24);
            // m(5);

            FormListParam f = new FormListParam(viTOV); f.ShowDialog();
            //m(55);

            if (f.IsOk)
            {
                viTOV[1].SubItems[1].Text = (f.listView1.Items[1].SubItems[1].Text);


                string sql_Update = string.Concat("UPDATE city.list_sc SET izm = '",
                    viTOV[1].SubItems[1].Text,
                    "' WHERE cod = ", ocodo);
               // h.m(sql_Update);
                q.UpdateData(sql_Update);
               // h.m(20);
            }

        }

        private void editParam_regular(object ocodo)
        {
            
            string sql = string.Concat("SELECT * FROM listregular l where cod = ", ocodo, ";");
            DataTable dt = q.selectAny(sql);

            
            ListViewItem[] viTOV = new ListViewItem[2];

            viTOV[0] = new ListViewItem("Наименование (код)");
            viTOV[1] = new ListViewItem("ДАТА РЕГ");// "Цена0 Приход"; 

            
            viTOV[0].ImageIndex = 5;
            viTOV[1].ImageIndex = 6;
           // m(45);
            viTOV[0].Tag = string.Concat((int)workType.nameCOD, "; name_cod");
            viTOV[1].Tag = string.Concat((int)workType.date, "; coddr");


            viTOV[0].SubItems.Add(functionService.nameCod.name_cod(dt.Rows[0]["name"], dt.Rows[0]["cod"]));
            viTOV[1].SubItems.Add(functionService.DATECOD.cod_to_date(  dt.Rows[0]["coddr"].ToString()));
           // m(46);
            viTOV[0].Font = new Font("Tahoma", 24);
            viTOV[1].Font = new Font("Tahoma", 24);
           // m(5);

            FormListParam f = new FormListParam(viTOV); f.ShowDialog();
            //m(55);

            if (f.IsOk)
            {
                viTOV[1].SubItems[1].Text = 
                    functionService.DATECOD.date_to_cod_str(f.listView1.Items[1].SubItems[1].Text);


                string sql_Update = string.Concat("UPDATE listregular SET coddr = ",
                    viTOV[1].SubItems[1].Text,
                    " WHERE cod = ", ocodo);

                //string sql_Update = string.Concat("UPDATE listregular SET coddr = ",
                //    viTOV[1].SubItems[1].Text,
                //    " WHERE cod = ", ocodo);
                q.UpdateData(sql_Update);
               
            }
            
        }
        
        private void editParam_SELECT(object ocodo)
        {

            string sql = string.Concat("SELECT * FROM ", city.pro_listselect ," where cod = ", ocodo, ";");
            DataTable dt = q.selectAny(sql);
            
            ListViewItem[] vi = new ListViewItem[2];

            vi[0] = new ListViewItem("Наименование (код)");
            vi[1] = new ListViewItem("ГРУППА");// "Цена0 Приход"; 
            
            vi[0].ImageIndex = 5;
            vi[1].ImageIndex = 6;
            // m(45);
            vi[0].Tag = string.Concat((int)workType.nameCOD, "; name_cod");
            vi[1].Tag = string.Concat((int)workType.text , "; cog");


            vi[0].SubItems.Add(functionService.nameCod.name_cod(dt.Rows[0]["name"], dt.Rows[0]["cod"]));
            vi[1].SubItems.Add(functionService.DATECOD.cod_to_date(dt.Rows[0]["cog"].ToString()));
            // m(46);
            vi[0].Font = new Font("Tahoma", 24);
            vi[1].Font = new Font("Tahoma", 24);
            // m(5);

            FormListParam f = new FormListParam(vi); f.ShowDialog();
            //m(55);

            if (f.IsOk)
            {
                vi[1].SubItems[1].Text = (f.listView1.Items[1].SubItems[1].Text);


                string sql_Update = string.Concat("UPDATE ", city.pro_listselect, " SET cog = '",
                    vi[1].SubItems[1].Text,
                    "' WHERE cod = ", ocodo);
                q.UpdateData(sql_Update);

            }
        }

        void f_add_Poluf(object codo, object nameo, object whereCondition0)
        {
            string name = nameo.ToString().Replace("(", "/").Replace(")", "/");
            int ic = Convert.ToInt32( q.selectScalar(string.Concat("select count(*) as cc from  city.list_tehsir_z WHERE ", whereCondition0, ";")));
            int imm = 1;
            if(ic>0)
            {
                imm = Convert.ToInt32
                    (q.selectScalar(
                     string.Concat( "select max(cod)+1 as codm from city.list_tehsir_z WHERE ",
                         whereCondition0, ";" )
                    )
                    )
                    ;
            }
            //list_sc_tehsir_z
            string sql = string.Concat("INSERT  city.list_tehsir_z (cod, name, izm) VALUES (", 
                imm, ", '", name, "', 'гр');");
            q.UpdateData(sql);

            string sql20 = string.Concat("DELETE FROM city.list_sc_tehsir_z WHERE codsc=", codo, ";");
            q.UpdateData(sql20);
            string sql2 = string.Concat("insert city.list_sc_tehsir_z(codsc, codts) VALUES (",codo ,",",imm ,");");
            q.UpdateData(sql2);
        }
        void f_del_Poluf(object codo)
        {
            int codts = Convert.ToInt32( q.selectScalar
                (string.Concat("select codts from  city.list_sc_tehsir_z WHERE codsc =", codo, ";")));
            string sql =
                string.Concat("delete from list_tehsir_z WHERE cod =", codts, ";");
            q.UpdateData(sql);
            string sql2 =
                string.Concat("delete from list_sc_tehsir_z WHERE codsc =", codo, ";");
            q.UpdateData(sql);
        }
        void f_edit_Poluf(object codo, object nameo)
        {
            string name = nameo.ToString().Replace("(", "/").Replace(")", "/");
            int codts = Convert.ToInt32(q.selectScalar
               (string.Concat("select codts from  city.list_sc_tehsir_z WHERE codsc =", codo, ";")));
            string sql = string.Concat("update list_tehsir_z  set name = '", name  ,"' WHERE cod =", codts, ";");
            q.UpdateData(sql); 
        }
        
        #endregion
       
        void deleg000(object oo)
        {
            functionService.shorts.m(5665554);
        }
        private void set_toolStripMenuItem6_text()
        {
            DataTable dt;
            string raz_pol_10 = q.tk(param.raz_pol_10);
            dt = q.selectAny(string.Concat("SELECT cod, name FROM ",
                           city.pro_listselect, " WHERE cog = 'raz_pol' ;"));
            listAny f = new listAny(dt); f.ShowDialog(); q.put(param.raz_pol_10, f.sText);
            toolStripMenuItem6.Text = raz_pol_10;

            if (raz_pol_10 == city.pro_listselect__user)
            {
                toolStripMenuItem47.Visible = false;
                toolStripMenuItem7.Visible = false;
            }
            else
            {
                toolStripMenuItem47.Visible = true;
                toolStripMenuItem7.Visible = true;
            }

        }
        private void dir12()
        {
            DirectoryInfo d = new DirectoryInfo("C:\\work\\donet\\city2");
            DirectoryInfo dip = d.Parent;
            string newName = string.Concat(d.Name, "_", functionService.DATECOD.get_Now_YearMonthDate_HourMinSec);
            DirectoryInfo dirNew = dip.CreateSubdirectory(newName);
        }
        private string get_directory_newName_datetimeNow
        {
            get
            {
                DirectoryInfo d = new DirectoryInfo("C:\\work\\donet\\city2");
                DirectoryInfo dip = d.Parent;
                string newName = string.Concat(d.FullName, "_", functionService.DATECOD.get_Now_YearMonthDate_HourMinSec);
                //DirectoryInfo dirNew = dip.CreateSubdirectory(newName);
                return newName;
            }
        }
        private void copyFiles(string adresDir, FileInfo[] ffo)
        {
            DirectoryInfo di = new DirectoryInfo(adresDir); di.Create();
            foreach (FileInfo fi in ffo)
            {
                fi.CopyTo(string.Concat(adresDir,"\\", fi.Name));
            }
        }
        private void copyDirectoryWithFiles( string strPATH)
        {
          // DirectoryInfo d = new DirectoryInfo("C:\\work\\donet\\city2");
           DirectoryInfo d = new DirectoryInfo(strPATH);
           DirectoryInfo[] ad =  d.GetDirectories();
           FileInfo[] ff = d.GetFiles(); 
            copyFiles(get_directory_newName_datetimeNow, ff);


            foreach (DirectoryInfo dc in ad)
            {
                DirectoryInfo[] ad1 = dc.GetDirectories();
                FileInfo[] fi = dc.GetFiles();
                copyFiles(string.Concat(get_directory_newName_datetimeNow, "\\", dc.Name), fi);

                foreach (DirectoryInfo dc1 in ad1)
                {
                    DirectoryInfo[] ad2 = dc1.GetDirectories();
                    FileInfo[] fi1 = dc1.GetFiles();
                    copyFiles(string.Concat(get_directory_newName_datetimeNow, "\\", dc.Name, "\\", dc1.Name), fi1);
                    foreach (DirectoryInfo dc2 in ad2)
                    {
                        DirectoryInfo[] ad3 = dc2.GetDirectories();
                        FileInfo[] fi2 = dc2.GetFiles();
                        copyFiles(string.Concat(get_directory_newName_datetimeNow, "\\", dc.Name, "\\", dc1.Name, "\\", dc2.Name), fi2);
                        foreach (DirectoryInfo dc3 in ad3)
                        {
                            FileInfo[] fi3 = dc3.GetFiles();
                            copyFiles(string.Concat(get_directory_newName_datetimeNow, "\\", dc.Name, "\\", dc1.Name, "\\", dc2.Name, "\\", dc3.Name), fi3);
                        }
                    }
                }
               functionService.shorts.m("ok");
           }

           


        }
        void t_tov_from_sklad()
        {
            q.con.setConn_mdb("C:\\work\\Sklad\\Sk4101.mdb");
            q.con.co_mdb(); 
            DataTable t = q.selectAnyMDB("select * from t;");
            string sql_dml;
            sql_dml = "delete from sir_listSir;"; q.UpdateData(sql_dml);
            foreach (DataRow r in t.Rows)
            {
                sql_dml = string.Concat("insert into city.sir_listsir(cod,name) value (", r[0] ,",'", r[1],"')"); q.UpdateData(sql_dml);
            }
            q.con.cc_mdb(); functionService.shorts.m("ok");
        }

        private void toolStripMenuItem14_Click_1(object sender, EventArgs e)
        {
            enterData.FormED2 f = new enterData.FormED2(); f.ShowDialog();
        }

        private void toolStripMenuItem43_Click(object sender, EventArgs e)
        {

        }

        private void toolStripMenuItem44_Click(object sender, EventArgs e)
        {

        }

        private void toolStripMenuItem17_Click_1(object sender, EventArgs e)
        {
            openListPlaces();
        }

        private void toolStripMenuItem46_Click(object sender, EventArgs e)
        {

        }

        private void toolStripMenuItem19_Click(object sender, EventArgs e)
        {
            q.put(param.sir_activTypeDoc_22, (int)raw.typeDoc.NKP );
        }

        private void toolStripMenuItem20_Click(object sender, EventArgs e)
        {
            q.put(param.sir_activTypeDoc_22, (int)raw.typeDoc.SFP);
        }

        private void toolStripMenuItem25_Click(object sender, EventArgs e)
        {
            q.put(param.sir_activTypeDoc_22, (int)raw.typeDoc.NKR);
        }

        private void toolStripMenuItem24_Click(object sender, EventArgs e)
        {
            q.put(param.sir_activTypeDoc_22, (int)raw.typeDoc.NKRS);
        }

        private void toolStripMenuItem20_Click_1(object sender, EventArgs e)
        {
            

        }

        private void toolStripMenuItem23_Click(object sender, EventArgs e)
        {
          

        }

        private void toolStripMenuItem24_Click_1(object sender, EventArgs e)
        {
            listAnyEdit f = new listAnyEdit(editParam_regular, "city", city.listregular, invert(bor));
            f.ShowDialog();

        }

        private void toolStripMenuItem25_Click_1(object sender, EventArgs e)
        {
            
        }

        private void toolStripMenuItem39_Click(object sender, EventArgs e)
        {

        }

        private void toolStripMenuItem21_Click(object sender, EventArgs e)
        {
           
        }

        private void toolStripMenuItem19_Click_1(object sender, EventArgs e)
        {
        }

        private void toolStripMenuItem27_Click(object sender, EventArgs e)
        { 
          
        }
        private void import_sklad_rd()
        {

            /*
             * Nd	      dd	    vd	corg	dp1	dp2	dp3
               41149039	01-янв-10	Сф	1159		0	01-янв-10
            */
            //city7.FormKEY f = new city7.FormKEY(); f.ShowDialog();
            q.con = new DB_SQL.ConnectionDB_SQL(q.tk(param.sir_path_to_skladMay_31));
            q.con.co_mdb();
            DataTable ts = q.selectAnyMDB(functionService.sql_sklad.rd_sklad(8280)); //q.sh(ts);

            string sql_dml = ""; string currentDate = ""; int ci = 0;
            q.con.pass =  q.tk(param.pass_inServ_55); q.con.co(q.tk(param.server_1));
            q.UpdateData("delete from sir_rd_sklad;");
            toolStripStatusLabel3.Text = "begin add after delete";
            for (int j = 0; j < ts.Rows.Count; j++)
            {
                if (j == 0) { currentDate = Convert.ToDateTime(ts.Rows[j][1]).ToShortDateString(); ci = 1; }

                if (j > 0)
                {
                    if (Convert.ToDateTime(ts.Rows[j][1]).ToShortDateString() == currentDate) { ci++; }
                    else { currentDate = Convert.ToDateTime(ts.Rows[j][1]).ToShortDateString(); ci = 1; }
                }
                sql_dml = functionService.sql_sklad.ADD_sir_rd_sklad(ci, ts.Rows[j][0], Convert.ToDateTime(ts.Rows[j][1]).ToShortDateString(),
                    ts.Rows[j][2], ts.Rows[j][3], ts.Rows[j][4], ts.Rows[j][5], Convert.ToDateTime(ts.Rows[j][6]).ToShortDateString()); q.UpdateData(sql_dml);
            }
            string sql_dmlUpdate = string.Concat("update sir_rd_sklad set ndn =  `city`.`coddSIR`(codd10913_from20100913(date(`city`.`dd_13_09_2010_convertTo_dd_2010_09_13`(dd))*1,2009),1, cod123);");
            q.UpdateData(sql_dmlUpdate);
            sql_dmlUpdate = string.Concat("call `city`.`sir_rd_from_sir_rd_sklad` (8280, 19 );");
            q.UpdateData(sql_dmlUpdate);
            h.m("Таблица реквизитов импортированна");
        }
        private void import_sklad_rd_all()
        {

            /*
             * Nd	      dd	    vd	corg	dp1	dp2	dp3
               41149039	01-янв-10	Сф	1159		0	01-янв-10
            */
            //city7.FormKEY f = new city7.FormKEY(); f.ShowDialog();
            q.con = new DB_SQL.ConnectionDB_SQL(q.tk(param.sir_path_to_skladMay_31));
            q.con.co_mdb();
            DataTable ts = q.selectAnyMDB(functionService.sql_sklad.sklad_rd_all());  //q.sh(ts);

            string sql_dml = ""; string currentDate = ""; int ci = 0;
            q.con.pass =  q.tk(param.pass_inServ_55); q.con.co(q.tk(param.server_1));
            q.UpdateData("delete from data.sklad_rd;");
             
            for (int j = 0; j < ts.Rows.Count; j++)
            {
              
                sql_dml = functionService.sql_sklad.ADD_data_sklad_rd(ts.Rows[j][0],
                    Convert.ToDateTime(ts.Rows[j][1]).ToShortDateString(),
                    ts.Rows[j][2], ts.Rows[j][3], ts.Rows[j][4], ts.Rows[j][5], 
                    Convert.ToDateTime(ts.Rows[j][6]).ToShortDateString()); 
                q.UpdateData(sql_dml);
            }
        }
        private void prep_sir_rd_sklad0()
        {

            /*
             * Nd	      dd	    vd	corg	dp1	dp2	dp3
               41149039	01-янв-10	Сф	1159		0	01-янв-10
            */
            //city7.FormKEY f = new city7.FormKEY(); f.ShowDialog();
            DataTable ts = new DataTable();
            string sql_dml = ""; string currentDate = ""; int ci = 0;
            q.con.pass =  q.tk(param.pass_inServ_55); q.con.co(q.tk(param.server_1));
          //  DataTable tt = q.selectAny("SELECT * FROM listtov l;"); q.sh(tt);
            //q.UpdateData("call `city`.`sir_rd_sklad__from__sklad_rd`(8280);");
            //h.m(q.selectScalar("SELECT count(*) FROM city.sir_rd_sklad s; "));
            q.UpdateData("delete from city.sir_rd_sklad;");
            q.UpdateData(h.a( "insert into city.sir_rd_sklad(nd, dd,vd,corg,dp1,dp2,dp3, cod123, ndn) ",
                " select Nd, date(dd) as dd, vd, corg, dp1, dp2, date(dp3), 0 as cod123, 0 as ndn",
                " from data.sklad_rd where corg=8280 and vd = 'Нк';"));
            //h.m(q.selectScalar("SELECT count(*) FROM city.sir_rd_sklad s; "));
            //q.UpdateData("call `city`.`sir_rd_sklad__from__sklad_rd`(8280);");
            //h.m(q.selectScalar("SELECT count(*) FROM city.sir_rd_sklad s; "));
            ts = q.selectAny("SELECT * FROM city.sir_rd_sklad s;");
            q.UpdateData("delete from city.sir_rd_sklad0;");
            for (int j = 0; j < ts.Rows.Count; j++)
            {
                if (j == 0) { currentDate = Convert.ToDateTime(ts.Rows[j][1]).ToShortDateString();  ci = 1; }

                if (j > 0)
                {
                    if (Convert.ToDateTime(ts.Rows[j][1]).ToShortDateString() == currentDate) { ci++; }
                    else { currentDate = Convert.ToDateTime(ts.Rows[j][1]).ToShortDateString(); ci = 1; }
                }
                sql_dml = functionService.sql_sklad.ADD_sir_rd_sklad(ci, ts.Rows[j][0], Convert.ToDateTime(ts.Rows[j][1]).ToShortDateString(),
                    ts.Rows[j][2], ts.Rows[j][3], ts.Rows[j][4], ts.Rows[j][5], Convert.ToDateTime(ts.Rows[j][6]).ToShortDateString()); q.UpdateData(sql_dml);
            }
            string sql_dmlUpdate = string.Concat("update sir_rd_sklad0 set ndn =  `city`.`coddSIR`(codd10913_from20100913(date( city.dd_13_09_2010_convertTo_dd_2010_09_13(dd))*1,2009),1, cod123);");
            q.UpdateData(sql_dmlUpdate);

            sql_dmlUpdate = string.Concat("delete from sir_rd_sklad;");
            q.UpdateData(sql_dmlUpdate);

            sql_dmlUpdate = string.Concat("insert into sir_rd_sklad (nd,dd,vd,corg,dp1,dp2,dp3,cod123,ndn) select * from sir_rd_sklad0;");
            q.UpdateData(sql_dmlUpdate);

            DataTable tst = q.selectAny("SELECT * FROM city.sir_rd_sklad s;"); q.sh(tst);
            h.m("Таблица реквизитов импортированна");
        }
        
        
        private void prep_skl_rd()
        {
            int yearDoc = Convert.ToDateTime(q.tk(ETALON.param.day_work_7)).Year;
            int monthDoc = Convert.ToDateTime(q.tk(ETALON.param.day_work_7)).Month;
            int year_monthCurrent_201103 = yearDoc * 100 + monthDoc;

            if (year_monthCurrent_201103 != 201012)
            {
              //  h.m(year_monthCurrent_201103, " call skl_prp_addFromSklad");
                q.UpdateData(string.Concat("call city.skl_prp_addFromSklad(", year_monthCurrent_201103, ", 0);"));
            }
            else
            {
              //  h.m(year_monthCurrent_201103, " call skl_prp_addFromSkladDECEMBER");
                q.UpdateData(string.Concat("call city.skl_prp_addFromSkladDECEMBER(", year_monthCurrent_201103, ", 0);"));
          
            }
        }

        int yearFrom_codYear_2(int codYear)
        {
             return 2009 + codYear;
        }

        private void prep_skl_rd_in1()
        {
            //string s64 = string.Concat(SMENA, 1300); 
            string s203 = SMENA.Substring(0,3);
            int codd_203301300 = 203311300;//Convert.ToInt32(s64);
            int codYear = Convert.ToInt32(s203.Substring(0,1));
           // h.m("codYear=", codYear, " s203=", s203, "  s203.Substring(0,1)=", s203.Substring(0, 1));
            int dd_year = yearFrom_codYear_2(codYear), ym=2009 , dd_m=1, dd_d=1;
            int dd_yc = 0;
            int codd000 = 0;

            string currentDate = "", readDate = "", sql_dml="";
            int ci = 0;
            dt_skl_rd = q.selectAny(
                string.Concat(
                "SELECT codd, nd, dd FROM citytemp", Month01 ,".sklad_rd_123 s order by dd, nd;")); //q.sh(dt_skl_rd);

            q.UpdateData(string.Concat("DELETE FROM citytemp", Month01, ".sklad_rd_123t;"));
          //  m(dd_yc);
            for (int j = 0; j < dt_skl_rd.Rows.Count; j++)
            {
              //  h.m(h.aa(dt_skl_rd.Rows[j][0], dt_skl_rd.Rows[j][1], dt_skl_rd.Rows[j][2]));
                dd_year = Convert.ToInt32( dt_skl_rd.Rows[j][2].ToString().Substring(0, 4));
               // h.m(h.aa(dt_skl_rd.Rows[j][0], dt_skl_rd.Rows[j][1], dt_skl_rd.Rows[j][2], " dd_year=", dd_year));
                dd_yc = dd_year - ym;
                
                dd_m = Convert.ToInt32(dt_skl_rd.Rows[j][2].ToString().Substring(4, 2));
                dd_d = Convert.ToInt32(dt_skl_rd.Rows[j][2].ToString().Substring(6, 2));
                
                codd_203301300 = ((dd_yc * 100 + dd_m) * 100 + dd_d) * 10000 + 1300;

                readDate = dt_skl_rd.Rows[j][2].ToString();

                if (j == 0) { currentDate = readDate; ci = 1; }

                if (j > 0)
                {
                    if (currentDate == readDate) { ci++; }
                    else { currentDate = readDate; ci = 1; }
                }
                //codd, nd, dd, vd, codo
                sql_dml = functionService.sql_sklad.insert_sklad_rd_123t(
                    codd_203301300 + ci, 
                    dt_skl_rd.Rows[j][1],
                    dt_skl_rd.Rows[j][2], Month01 
                    );
             //   h.m(h.aa(dt_skl_rd.Rows[j][1], (dt_skl_rd.Rows[j][2]), ci, codd_203301300));
                q.UpdateData(sql_dml);
            }
            q.UpdateData(string.Concat("DELETE FROM citytemp", Month01, ".sklad_rd_123;"));
            q.UpdateData(functionService.sql_sklad.insert_sklad_rd_123__from__sklad_rd_123t(Month01));
            //q.UpdateData("DELETE FROM city.sklad_rd_123t;");

            string sql_dml2 = string.Concat("call `city`.`skl_add` (", s203, ");"); //m(sql_dml2 );
          
            q.UpdateData(sql_dml2);
        }

        private void prep_SKLAD()
        {
            string sm = q.tk(ETALON.param.kafe_smena_42).Substring(0, 3);
            q.con.co(q.tk(param.server_1));
            // add_NewSir_in_sir_listsir_ts - добавляет новое сырье в   sir_listsir_ts
            // sir_listsir_ts-таблица соответствия сырья со склада и технологического сырья
            // для нового сырья ставится признак 888 - неопределенное сырье,
            // который нужно заменить пользователю на необходимое соответствие



            q.UpdateData( h.aa( "call `city`.`add_NewSir_in_sir_listsir_ts` (", sm ,");"));

            object occ = q.selectScalar("select count(*) as cc from city.sir_listsir_ts where codts=888;");
            if (Convert.ToInt32(occ) > 0)
            {
                h.m("Есть новое сырье в таблице соответствия между СЫРЬЕМ И ТЕХНОЛОГИЧЕСКИМ СЫРЬЕМ. Проставьте соответствия и после этого повторите операцию.");
                city7.FormSirTehSir f = new city7.FormSirTehSir(); f.ShowDialog(); q.put(64, h.TRUFAL(vv.sirTehSir.trueMemo));
                vv.message = "Импорт остановлен";
            }
            else
            {

                prep_skl_rd();// h.m("prep_skl_rd");
                prep_skl_rd_in1();

                vv.message = "Выполнено";
            }
        }

        
        private void prep_sir_listsir()
        {
           
            q.UpdateData("delete from city.sir_listsir;");
            q.UpdateData("insert into city.sir_listsir(cod, name) select ct, t from data.sklad_t;");

        }
        private void prep_sir_rd_sklad()
        {

            /*
             * Nd	      dd	    vd	corg	dp1	dp2	dp3
               41149039	01-янв-10	Сф	1159		0	01-янв-10
            */
            //city7.FormKEY f = new city7.FormKEY(); f.ShowDialog();
            DataTable ts = new DataTable();
            string sql_dml = ""; 
            string currentDate = "";
            int currentMoth = 
                Convert.ToDateTime(q.tk(param.day_work_7)).Month
                , currentCorg = q.tk_int(param.corg_import_fromSklad_59);
            //h.m(h.aa(currentMoth, currentCorg));

            int ci = 0;
            q.con.pass =  q.tk(param.pass_inServ_55); q.con.co(q.tk(param.server_1));
           string  sm = q.tk(ETALON.param.kafe_smena_42).Substring(0, 3);
            q.UpdateData("delete from city.sir_listsir;");
            q.UpdateData("insert into city.sir_listsir(cod, name) select ct, t from data.sklad_t;");

            /*insert into city.sir_listsir(cod, name)
select ct,t from data.sklad_t;*/

            q.UpdateData("delete from city.sir_rd_sklad;");
            //q.UpdateData(h.a("insert into city.sir_rd_sklad(nd, dd,vd,corg,dp1,dp2,dp3, cod123, ndn) ",
            //    " select Nd, date(dd) as dd, vd, corg, dp1, dp2, date(dp3), 0 as cod123, 0 as ndn",
            //    " from data.sklad_rd where corg=8280 and vd = 'Нк';"));

            q.UpdateData(h.a("insert into city.sir_rd_sklad(nd, dd,vd,corg,dp1,dp2,dp3, cod123, ndn) ",
                " select Nd, date(dd) as dd, vd, corg, dp1, dp2, date(dp3), 0 as cod123, 0 as ndn",
                " from data.sklad_rd where corg=", currentCorg
                , " and vd = 'Нк' and Month(date(dd))=", currentMoth, ";"));
            ts = q.selectAny("SELECT * FROM city.sir_rd_sklad s order by nd, dd;");
            q.UpdateData("delete from city.sir_rd_sklad;");
            for (int j = 0; j < ts.Rows.Count; j++)
            {
                if (j == 0) { currentDate = functionService.DATECOD.date_to_cod_str(ts.Rows[j][1]); ci = 1; }

                if (j > 0)
                {
                    if (currentDate == functionService.DATECOD.date_to_cod_str(ts.Rows[j][1])) { ci++; }
                    else { currentDate = functionService.DATECOD.date_to_cod_str(ts.Rows[j][1]); ci = 1; }
                }
                sql_dml = functionService.sql_sklad.ADD_sir_rd_sklad(ci, ts.Rows[j][0],
                    Convert.ToDateTime(ts.Rows[j][1]).ToShortDateString(),
                    ts.Rows[j][2], ts.Rows[j][3], ts.Rows[j][4], ts.Rows[j][5],
                    Convert.ToDateTime(ts.Rows[j][6]).ToShortDateString());
                //h.m(h.aa(ts.Rows[j][0], Convert.ToDateTime(ts.Rows[j][1]).ToShortDateString(), ci));
                q.UpdateData(sql_dml);
            }
            string sql_dmlUpdate = 
                string.Concat("update sir_rd_sklad set ndn = `city`.`coddSIRprih`(codd10913_from20100913(date( city.dd_13_09_2010_convertTo_dd_2010_09_13(dd))*1,2009),1, cod123);");
            q.UpdateData(sql_dmlUpdate);

            //q.UpdateData("call `city`.`sir_td_from_td_sklad`( );");
            //q.UpdateData("update city.sir_td set crd = round(crd,2), deb=round(deb,2), pr=round(pr,3),kol=round(kol,2);");
           
            //DataTable tst = q.selectAny("SELECT * FROM city.sir_rd_sklad s;"); q.sh(tst);
            h.m("Данные со склада импортированны");
            //ранее подготавливаются таблицы  sir_rd_sklad sir_td_sklad
            //которые используються в процедуре  /select_FROM_sir_rd_sklad__to__sir_rd__and_Td_m/
            // подготавливающей таблицы  sir_rd sir_td 
            // добавляющиеся документы содержат codd типа 203081302
            // где 2-год 03-месяц 08-число месяца 1-тип документа приход 3-зарезер под приход со склада 2-номер приходного документа в этом дне
            q.UpdateData(string.Concat("call `city`.`select_FROM_sir_rd_sklad__to__sir_rd__and_Td_m`(", functionService.nameCod.readCod(q.tk(param.o_l_0)) ,");"));
            q.UpdateData(string.Concat("call `city`.`add_sir_listsir_ts`(",sm,");"));

            //q.UpdateData("delete from sir_listsir_ts where codTs=888;");
            object o0 = q.selectScalar("select count(cod) from sir_listsir_ts where codTs = 888;");
            if (h.i(o0) > 0)
            {
                h.m("Имеются не указанные соответствия между сырьем склада и технологическим сырьем. Проставьте соответствия");
                city7.FormSirTehSir f = new city7.FormSirTehSir(); f.ShowDialog();

                q.put(64, h.TRUFAL(vv.sirTehSir.trueMemo));
            }

            h.m("Данные со склада добавлены в директорию документов");
        }

        private int true1false0(bool btrueFalse)
        {
            int i=0;
            if (vv.sirTehSir.trueMemo) { i = 1; } else { i = 0; }
            return i;
        }
        
        private void import_sklad_td_all()
        {

            /*
             * Nd	      dd	    vd	corg	dp1	dp2	dp3
               41149039	01-янв-10	Сф	1159		0	01-янв-10
            */
            //city7.FormKEY f = new city7.FormKEY(); f.ShowDialog();
            q.con = new DB_SQL.ConnectionDB_SQL(q.tk(param.sir_path_to_skladMay_31));
            q.con.co_mdb();
            DataTable ts = q.selectAnyMDB(functionService.sql_sklad.td_sklad(8280)); //q.sh(ts);

            string sql_dml = "";
            q.con.pass =  q.tk(param.pass_inServ_55); q.con.co(q.tk(param.server_1));
            q.UpdateData("delete from sir_td_sklad;");
            for (int j = 0; j < ts.Rows.Count; j++)
            {
                //                                                   ndt, pp, sk, ct, p2, p1, mt, mnt1, mnt2, nds, crd, db, sopp, nsk, p5t
                sql_dml = functionService.sql_sklad.ADD_sir_td_sklad(ts.Rows[j][0], ts.Rows[j][1], ts.Rows[j][2], ts.Rows[j][3], ts.Rows[j][4].ToString().Replace(',', '.'),
                                                                     ts.Rows[j][5].ToString().Replace(',', '.'), ts.Rows[j][6].ToString().Replace(',', '.'), ts.Rows[j][7].ToString().Replace(',', '.'), ts.Rows[j][8].ToString().Replace(',', '.'), ts.Rows[j][9].ToString().Replace(',', '.'),
                                                                     ts.Rows[j][10].ToString().Replace(',', '.'), ts.Rows[j][11].ToString().Replace(',', '.'), ts.Rows[j][12], ts.Rows[j][13], ts.Rows[j][14]);
                //h.m(sql_dml);
                q.UpdateData(sql_dml);
            }
            ////string sd, sc; string sd0, sc0;//for (int j = 0; j < ts.Rows.Count; j++)
            ////for (int j = 0; j < 3; j++)
            ////{
            ////    sd = ts.Rows[j][10].ToString(); sd0 = sd.Replace(',','.');
            ////    sc = ts.Rows[j][11].ToString(); sc0 = sd.Replace(',', '.');
            ////    sql_dml = functionService.sql_sklad.ADD_sir_td_sklad(ts.Rows[j][0], 
            ////        ts.Rows[j][1], ts.Rows[j][2], ts.Rows[j][3],
            ////        ts.Rows[j][4].ToString().Replace(",", "."),
            ////        ts.Rows[j][5].ToString().Replace(",", "."),
            ////        ts.Rows[j][6].ToString().Replace(",", "."),
            ////        ts.Rows[j][7].ToString().Replace(",", "."),
            ////        ts.Rows[j][8].ToString().Replace(",", "."),
            ////        ts.Rows[j][9].ToString().Replace(",", "."),
            ////        ts.Rows[j][10].ToString().Replace(",", "."), 
            ////        ts.Rows[j][11].ToString().Replace(",", "."), 
            ////        ts.Rows[j][12], ts.Rows[j][13], ts.Rows[j][14]);
            ////    h.m(h.az(sd, sd0, sc, sc0, sql_dml));
            ////    //q.UpdateData(sql_dml);
            ////}
            h.m("Таблица товаров импортированна");
        }
        private void import_sklad_td()
        {

            /*
             * Nd	      dd	    vd	corg	dp1	dp2	dp3
               41149039	01-янв-10	Сф	1159		0	01-янв-10
            */
            //city7.FormKEY f = new city7.FormKEY(); f.ShowDialog();
            q.con = new DB_SQL.ConnectionDB_SQL(q.tk(param.sir_path_to_skladMay_31));
            q.con.co_mdb();
            DataTable ts = q.selectAnyMDB(functionService.sql_sklad.td_sklad(8280)); //q.sh(ts);

            string sql_dml = "";
            q.con.pass =  q.tk(param.pass_inServ_55); q.con.co(q.tk(param.server_1));
            q.UpdateData("delete from sir_td_sklad;");
            for (int j = 0; j < ts.Rows.Count; j++)
            {
                //                                                   ndt, pp, sk, ct, p2, p1, mt, mnt1, mnt2, nds, crd, db, sopp, nsk, p5t
                sql_dml = functionService.sql_sklad.ADD_sir_td_sklad(ts.Rows[j][0], ts.Rows[j][1], ts.Rows[j][2], ts.Rows[j][3], ts.Rows[j][4].ToString().Replace(',', '.'),
                                                                     ts.Rows[j][5].ToString().Replace(',', '.'), ts.Rows[j][6].ToString().Replace(',', '.'), ts.Rows[j][7].ToString().Replace(',', '.'), ts.Rows[j][8].ToString().Replace(',', '.'), ts.Rows[j][9].ToString().Replace(',', '.'),
                                                                     ts.Rows[j][10].ToString().Replace(',', '.'), ts.Rows[j][11].ToString().Replace(',', '.'), ts.Rows[j][12], ts.Rows[j][13], ts.Rows[j][14]);
                //h.m(sql_dml);
                q.UpdateData(sql_dml);
            }
            ////string sd, sc; string sd0, sc0;//for (int j = 0; j < ts.Rows.Count; j++)
            ////for (int j = 0; j < 3; j++)
            ////{
            ////    sd = ts.Rows[j][10].ToString(); sd0 = sd.Replace(',','.');
            ////    sc = ts.Rows[j][11].ToString(); sc0 = sd.Replace(',', '.');
            ////    sql_dml = functionService.sql_sklad.ADD_sir_td_sklad(ts.Rows[j][0], 
            ////        ts.Rows[j][1], ts.Rows[j][2], ts.Rows[j][3],
            ////        ts.Rows[j][4].ToString().Replace(",", "."),
            ////        ts.Rows[j][5].ToString().Replace(",", "."),
            ////        ts.Rows[j][6].ToString().Replace(",", "."),
            ////        ts.Rows[j][7].ToString().Replace(",", "."),
            ////        ts.Rows[j][8].ToString().Replace(",", "."),
            ////        ts.Rows[j][9].ToString().Replace(",", "."),
            ////        ts.Rows[j][10].ToString().Replace(",", "."), 
            ////        ts.Rows[j][11].ToString().Replace(",", "."), 
            ////        ts.Rows[j][12], ts.Rows[j][13], ts.Rows[j][14]);
            ////    h.m(h.az(sd, sd0, sc, sc0, sql_dml));
            ////    //q.UpdateData(sql_dml);
            ////}
            h.m("Таблица товаров импортированна");
        }
        private void importNkPrihodaSoSklada_RD()
        {
            /*
             * Nd	      dd	    vd	corg	dp1	dp2	dp3
               41149039	01-янв-10	Сф	1159		0	01-янв-10
            */
            //city7.FormKEY f = new city7.FormKEY(); f.ShowDialog();
            q.con = new DB_SQL.ConnectionDB_SQL(q.tk(param.sir_path_to_skladMay_31));
            q.con.co_mdb();
            DataTable ts = q.selectAnyMDB(functionService.sql_sklad.rd_sklad(8280)); //q.sh(ts);
           
            string sql_dml = ""; int idd=0; 
            string scodsotr = vv.o_l_0_cod.ToString(), 
                scodd = "";
            q.con.pass =  q.tk(param.pass_inServ_55); q.con.co(q.tk(param.server_1));
            q.UpdateData("delete from sir_rd_sklad;");
            toolStripStatusLabel3.Text = "begin add after delete";
            for (int j = 0; j < ts.Rows.Count; j++)
            {
                idd = da.codDATE_10913_from_DATETIME(ts.Rows[j][1]); scodd = string.Concat(idd,(int)raw.typeDoc.NKP, h.nnn(j+1) );
                sql_dml = sql_doc.ADD_rd(scodd, ts.Rows[j][3], da.date_to_cod_int( ts.Rows[j][1]), scodsotr, ts.Rows[j][0]); q.UpdateData(sql_dml);
                toolStripStatusLabel3.Text = ts.Rows[j][0].ToString();
            }
            h.m("ok"); 
        }
        private void importNkPrihodaSoSklada_TD()
        {

        }

        private void toolStripMenuItem10_Click_1(object sender, EventArgs e)
        {
           // enumRead123();
          //  importNkPrihodaSoSklada_RD();
            //import_sklad_rd();
            prep_sir_rd_sklad();
            //import_sklad_td();
        }
        private void addNewRow(DataTable dto, object  ocod, object oname, object oprim)
        {
            DataRow r;
            r = dto.NewRow();
            r[0] = ocod; r[1] = oname ; r[2] = oprim;
            dto.Rows.Add(r);
            dto.AcceptChanges();

        }
        private void enumRead123()
        {
            int ix = 0;
            Type tt = typeof(param);  System.Array ar = Enum.GetValues(tt);
           int[] cip = new int[ar.Length]; int j=0;
           foreach (object o in ar)
           {
               cip[j] = Convert.ToInt32(o); j++;
           }


           DataTable ttt  = lookDir_And_ReadFile_To_DataTable("PLP").Copy();
              int[] cix = new int[ttt.Rows.Count]; int i = 0;
           foreach (DataRow r in ttt.Rows)
           {
              cix[i] = Convert.ToInt32(r[0]); i++;
           }
           bool IsHere;// = false;
           foreach (int p in cip)
           {
               //h.m(p);
               IsHere = false;
               foreach (int x in cix)
               {
                   //h.m(h.aa(p, "=", x));
                   if (p == x) { IsHere = true; }
               }
               if (IsHere == false) addNewRow(ttt, p, 0, Enum.GetName(tt,p));
           }

           ttt.WriteXml("PLP\\PLP.xml", XmlWriteMode.WriteSchema);
           h.m(h.aa(ttt.Rows.Count, "ok"));
        }
        private DataTable lookDir_And_ReadFile_To_DataTable(string fileName)
        {
            DataTable t = new DataTable();
            string s = "";
            if (lookDir(fileName))
            {
                s = string.Concat("PLP\\", fileName, ".xml");
                t.ReadXml(s);
                return t;
            }
            else return null;
        }
        private bool lookDir(string fileName)
        {
            bool IsHere = false;
            DirectoryInfo di = new DirectoryInfo("PLP");
            FileInfo[] fai = di.GetFiles();
            foreach (FileInfo fi in fai)
            {
                if (fileName == fi.Name.Replace(".xml", "")) { IsHere = true; break; }
            }
            return IsHere;
        }

        private void toolStripButton7_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void toolStripMenuItem29_Click(object sender, EventArgs e)
        {

            //DataTable dt = q.selectAny(string.Concat( "call `city`.`sir_period` (20101001, 20101030);"));
            DataTable dt = q.selectAny(string.Concat("call `city`.`sir_period` (", q.tk_int_codDate_fromDate(param.period_s_5), ", ", q.tk_int_codDate_fromDate(param.period_p_6), ");"));
            int[] ai = new int[] { 680, 95, 210 };
            string[] ass = new string[] { "Наименование", "Кол", "Сумма" };
            DataGridViewContentAlignment[] daaa = new DataGridViewContentAlignment[] { DataGridViewContentAlignment.MiddleLeft, DataGridViewContentAlignment.MiddleRight, DataGridViewContentAlignment.MiddleRight };

            ETALON.FormGridSelect f = new FormGridSelect(dt,ai,ass,daaa ); f.ShowDialog();
        }

        private void toolStripMenuItem30_Click(object sender, EventArgs e)
        {
            //city7.readEnum.G770(city7.plp_enum.plp.o_l_0);
          //  city7.readEnum.GetDescriptions<city7.plp_enum.plp>();
           // city7.readEnum.plp_r2();t
            string curSm = q.tk((int)param.kafe_smena_42),
                   openSm = q.tk((int)param.kafe_open_smena_43);
            int icurSm = Convert.ToInt32(curSm), 
                iopenSm = Convert.ToInt32(openSm);
            if (icurSm != iopenSm || (iopenSm == 0 || icurSm>iopenSm))
            { 
                fr.OpName =vv.o_l_0_name  ;//q.tk_name(param.o_l_0);
                fr.Psw = "AERF";
                fr.DevName = "COM1";
                fr.FlagOem = 1;

                fr.FROpenDLL();
               // fr.FRShiftOpen("смена 112140");
                fr.FRShiftOpen(q.tk((int)param.kafe_smena_42));
                fr.FRCloseDLL();
                q.put((int)param.kafe_open_smena_43, curSm);
                Application.Exit();
            }
            else if (iopenSm == icurSm || iopenSm > icurSm)
            {
                h.m(string.Concat("Смена ", icurSm ," уже открыта"));
            }
            
        }

        private void toolStripMenuItem34_Click_1(object sender, EventArgs e)
        {

            string sql_dml = "delete from city.sir_t_codd;"; q.UpdateData(sql_dml);
            sql_dml = "insert into city.sir_t_codd(name, sd, nd) SELECT city.name_cod( concat( s.vd, ' ', s.dd), s.nd) as name, s.dp1 as sd, s.nd as nd FROM sir_rd_sklad s left join sir_rd c on s.nd=c.coddSklad where isnull(coddSklad);";
            q.UpdateData(sql_dml);
            DataTable d4 = q.selectAny(" select name, sd from city.sir_t_codd;");  //q.sh(d4);
            ETALON.FormGridSelect f = new FormGridSelect(d4); f.ShowDialog();

            string sql = string.Concat("call `city`.`select_DOC_forADD_step2`(16);");
            q.UpdateData(sql);

        }

        private void toolStripMenuItem31_Click(object sender, EventArgs e)
        {
            FormDocZ f = new FormDocZ(); f.ShowDialog();
        }

        private void toolStripMenuItem33_Click_1(object sender, EventArgs e)
        {

        }

        private void toolStripMenuItem26_Click(object sender, EventArgs e)
        {
          //  call `city`.`select_rez` ();
            openRez();
        }
        private void openRez()
        {
            DataTable dt = q.selectAny("call `city`.`select_rez`();");
            city7.FormRzpt f = new city7.FormRzpt(dt);
            f.ShowDialog();
        }
        private void toolStripMenuItem41_Click_1(object sender, EventArgs e)
        {                         // \\May\c\Work\Sklad\Skltabl
            vv.path_sklad_import =  "\\\\May\\c\\Work\\Sklad\\Skltabl\\Skl4117.mdb";
            string slokal = q.tk(63); // 1-local 0 -po seti
            if (slokal == "1") { vv.path_sklad_import = "c:\\Work\\donet\\Skl4117.mdb";}
           

            string s203 = SMENA.Substring(0, 3);
           //////// prepImport();
           
           //if (System.Windows.Forms.MessageBox.Show("Сформировать документы прихода в цех СИТИ на основе технологического сырья", "Выбор", MessageBoxButtons.OKCancel) == DialogResult.OK)
           //{

            // setPricesInTD();        
           
           
                   if (s203 == "112")
                   {
                       importFromSkladDecember();
                   }
                   else 
                   {
                       importFromSklad();
                   }

                   string sql_dml = string.Concat("call `city`.`avgPR2`(", s203, ");"); //h.m(sql_dml);
                          q.UpdateData(sql_dml);
                          sql_dml = string.Concat("call `city`.`avgPR222`(", s203, ");"); //h.m(sql_dml);
                          q.UpdateData(sql_dml);
                   h.m(vv.message);
           
            //}
        }
        private void setPricesInTD()
        {
            DataTable tpr = q.selectAny("select * from sir_ts_pr;");
            int ic = tpr.Rows.Count; string sql_dml = "";// string.Concat();
            for (int i = 0; i < ic; i++)
            {
                sql_dml = string.Concat("update sir_td_z set pr = ",  tpr.Rows[i][1].ToString().Replace(",",".") ," where ct = ", tpr.Rows[i][0] ,";");
                q.UpdateData(sql_dml);
            }
        }
        private void prepImport()
        {
            //t_tov_from_sklad();
            string s = "call `city`.`sir_rd_sklad__from__sklad_rd`(8280);"; q.UpdateData(s); //h.m(" call ok");
            string sql = string.Concat("call `city`.`select_DOC_forADD`();"); DataTable dtt = q.selectAny(sql); q.sh(dtt);
            //  string sql = string.Concat("select name, sd from city.sir_t_codd;"); DataTable dtt = q.selectAny(sql); q.sh(dtt);

        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void toolStripMenuItem18_Click(object sender, EventArgs e)
        {
            openListSirTehnolog();
        }

        private void toolStripMenuItem42_Click_1(object sender, EventArgs e)
        {
            

            string curSm = q.tk((int)param.kafe_smena_42),
                   closeSm = q.tk((int)param.kafe_close_smena_44 ),
                   openSm = q.tk((int)param.kafe_open_smena_43);
            int icurSm = Convert.ToInt32(curSm),
                icloseSm = Convert.ToInt32(closeSm),
                iopenSm = Convert.ToInt32(openSm);
            if ((icurSm != icloseSm || (icloseSm == 0 || icurSm > icloseSm)) && (icloseSm != iopenSm))
            {

                fr.OpName = vv.o_l_0_name  ;//q.tk_name(param.o_l_0);
                fr.Psw = "AERF";
                fr.DevName = "COM1";
                fr.FlagOem = 1;

                fr.FROpenDLL();
                fr.FRShiftClose();
                fr.FRCloseDLL();
                q.put((int)param.kafe_close_smena_44 , curSm);

                //if (q.tk((int)param.sendData_to_EMAIL_52) == "1") 
                    sendDataToEMAIL();

                
                Application.Exit();
                /*
                fr.OpName = q.tk_name(param.o_l_0);
                fr.Psw = "AERF";
                fr.DevName = "COM1";
                fr.FlagOem = 1;

                fr.FROpenDLL();
                // fr.FRShiftOpen("смена 112140");
                fr.FRShiftOpen(q.tk((int)param.kafe_smena_42));
                fr.FRCloseDLL();
                q.put((int)param.kafe_open_smena_43, curSm);
                Application.Exit();
                 * */
            }
            else if (icloseSm == icurSm || icloseSm > icurSm || icloseSm == iopenSm )
            {
                h.m(string.Concat("Смена ", icurSm, " уже закрыта"));
            }
            
        }

        private void toolStripMenuItem43_Click_1(object sender, EventArgs e)
        {
            lookpass();
        }

        private void setEnabledItem(bool trueYes_FalseNo)
        {
            //2 21 12 3 28 13 4
            toolStripMenuItem2.Enabled = trueYes_FalseNo;
            toolStripMenuItem21.Enabled = trueYes_FalseNo;
            toolStripMenuItem12.Enabled = trueYes_FalseNo;
            toolStripMenuItem3.Enabled = trueYes_FalseNo;
            toolStripMenuItem28.Enabled = trueYes_FalseNo;
            toolStripMenuItem13.Enabled = trueYes_FalseNo;
        }

        private void lookpass()
        {
            q.con.pass = q.tk(param.pass_inServ_55); q.con.co(q.tk(param.server_1)); 

            listAny a = new listAny();

            password.pass f = new password.pass(); f.ShowDialog(); q.put((int)param.pass_11, f.sPassword);
            string s2 = f.sPassword; string spasss = f.sPassword;

            DataTable dt = q.selectAny("select cod, name, pass from lists.sot_listsot;");
            dt.AcceptChanges();
            bool b = false; string sn, spass = "-", sns = "-";//, cod_mark = "0", pcname = "-";

            foreach (DataRow r in dt.Rows)
            {
                sn = string.Concat(r[1], " (", r[0], ")"); spass = Convert.ToString(r[2]);
                // m(l.l.k(spass, " ", spasss));
                if (spass == spasss)
                {
                    b = true; sns = sn;
                    q.put((int)param.o_l_0, sns); vv.o_l_0 = sns;
                    string s = q.tk((int)param.prava_adm_56);
                    bor = s.Contains(string.Concat(";",r[0].ToString(),";"));
                    if (bor == true)     {  setEnabledItem(true);   }
                    else                 {  setEnabledItem(false);  }
                }
            }

            if (b == true)
            {
                setEnabledItem(true );

                readData_S_PO_InSQLSERVER();
                setItemsMain();
                toolStripMenuItem43.Enabled = false;
            }
            else
            {
                setEnabledItem(false);
               h.m("Введен не верный код доступа");
            }
        }

        private void toolStripMenuItem45_Click_1(object sender, EventArgs e)
        {
            
        }

        private void toolStripMenuItem44_Click_1(object sender, EventArgs e)
        {
            FormZl f = new FormZl(); f.ShowDialog();
        }

        private void toolStripMenuItem46_Click_1(object sender, EventArgs e)
        {
            
        }


        private void toolStripMenuItem54_Click(object sender, EventArgs e)
        {
            string ss = q.tk((int)param.kafe_smena_42);
            DataTable t = q.selectAny(string.Concat("call `city`.`smena_ct`(", ss, ");"));
            city7.FormLookProd f = new city7.FormLookProd(t, ss); f.ShowDialog();
        }

        private void toolStripMenuItem55_Click(object sender, EventArgs e)
        {
            string ss = q.tk((int)param.kafe_smena_42);
            DataTable t = q.selectAny(string.Concat("call `city`.`smena_codd_all` (", ss, ");"));
            city7.FormLookCheky f = new city7.FormLookCheky(t, ss); f.ShowDialog();
        }

        private void toolStripMenuItem52_Click(object sender, EventArgs e)
        {
            string ss = q.tk((int)param.kafe_smena_42);
            DataTable t = q.selectAny(string.Concat("call `city`.`smena_ct_f` (", ss, ");"));
            city7.FormLookProd f = new city7.FormLookProd(t, ss); f.ShowDialog();
        }

        private void toolStripMenuItem53_Click(object sender, EventArgs e)
        {
            string ss = q.tk((int)param.kafe_smena_42);
            DataTable t = q.selectAny(string.Concat("call `city`.`smena_codd_f` (", ss, ");"));
            city7.FormLookCheky f = new city7.FormLookCheky(t, ss); f.ShowDialog();
        }
        #region вывод на печать
        private void printReport_AnyTable(DataTable dto, string strHeaderTable, string itog)
        {
            fr.OpName = vv.o_l_0_name; //q.tk_name(param.o_l_0);
            fr.Psw = "AERF";
            fr.DevName = "COM1";
            fr.FlagOem = 1;

            fr.FROpenDLL();
            fr.FRStartSeans();
            fr.FRFDocPrintDataTable(dto, strHeaderTable, itog);
            fr.FRCloseDLL();
            
            Console.Write(fr.str);
        }
        private void printReport_smena_codd_all()
        {
            string ss = q.tk((int)param.kafe_smena_42);
            DataTable t = q.selectAny(string.Concat("call `city`.`smena_codd_all` (", ss, ");"));
            printReport_AnyTable(t, string.Concat("Смена ", ss, " все заказы"), timePrint);
        }
        private void printReport_smena_codd_f()
        {
            string ss = q.tk((int)param.kafe_smena_42);
            DataTable t = q.selectAny(string.Concat("call `city`.`smena_codd_f` (", ss, ");")); //q.sh(t);
            printReport_AnyTable(t, string.Concat("Смена ", ss, " фискализированные чеки"), timePrint);
        }
        private string timePrint
        {
           get
           {  
               return string.Concat("Время печати: ", DateTime.Now.ToLongTimeString());
           }
        }
        private void printReport_smena_ct_f()
        {
            string ss = q.tk((int)param.kafe_smena_42);
            DataTable t = q.selectAny(string.Concat("call `city`.`smena_ct_f` (", ss, ");"));
            
            
            DataTable t2 = new DataTable("tp");  t2.Columns.Add("name", typeof(string ));  t2.Columns.Add("sd", typeof(double));  t2.AcceptChanges();

            int ic = t.Rows.Count;          DataRow r;
            for (int i = 0; i < ic; i++)
            {
                r = t2.NewRow();
                r[0] = string.Concat(t.Rows[i][0], " ", t.Rows[i][1], "*", t.Rows[i][2]," ");
                r[1] = t.Rows[i][3];
                t2.Rows.Add(r);
            }
            t2.AcceptChanges();
            printReport_AnyTable(t2, string.Concat("Смена ",ss ," асс-т по фиск. чекам"),  timePrint );
        }
        private void printReport_smena_ct()
        {
            string ss = q.tk((int)param.kafe_smena_42);
            DataTable t = q.selectAny(string.Concat("call `city`.`smena_ct` (", ss, ");"));


            DataTable t2 = new DataTable("tp");
            t2.Columns.Add("name", typeof(string));
            t2.Columns.Add("sd", typeof(double));
            t2.AcceptChanges();

            int ic = t.Rows.Count;
            DataRow r;
            for (int i = 0; i < ic; i++)
            {
                r = t2.NewRow();
                r[0] = string.Concat(t.Rows[i][0], "....", t.Rows[i][1], "*", t.Rows[i][2], " ");
                r[1] = t.Rows[i][3];
                t2.Rows.Add(r);
            }
            t2.AcceptChanges();
            printReport_AnyTable(t2, string.Concat("Смена ", ss, " асс-т по всем заказам"), timePrint);
        }
        #endregion
        private void toolStripMenuItem45_Click_2(object sender, EventArgs e)
        {
            printReport_smena_ct_f();
        }

        private void toolStripMenuItem46_Click_2(object sender, EventArgs e)
        {
            printReport_smena_codd_f();
        }

        private void toolStripMenuItem56_Click(object sender, EventArgs e)
        {
            printReport_smena_ct();
        }

        private void toolStripMenuItem57_Click(object sender, EventArgs e)
        {
            printReport_smena_codd_all();
        }

        private void toolStripMenuItem58_Click(object sender, EventArgs e)
        {
            
           
        }

        private void sendTo_email(string adresEMAIL)
        {
            //"kokonev@list.ru"
            string smena = q.tk((int)param.kafe_smena_42);
            string s = string.Concat("Закрыта смена ", smena, " Сумма по по кассе:", MI_SUMMA_CASSA_L, " время", DateTime.Now.ToLongTimeString());
            HK.Service.Email.SendEmail_FromMailRuKokonev(adresEMAIL, s, "-");
           // h.m(h.a("Сумма по смене отправлена на адрес ", adresEMAIL));
        }
        private void sendDataToEMAIL() 
        {
            h.m("Будет выполнена отправка данных по интернету. Ждите.");

            string stag = q.tk((int)param.email_adreses_53);
            string[] ars  = stag.Split(';');

            for (int i = 0; i < ars.Length; i++)
            {
                sendTo_email(ars[i]);
            }
            /*
               sendTo_email("kokonev@list.ru"); // seedcorp@mail.ru
            // sendTo_email("6496384@gmail.com");
            sendTo_email("1086688@gmail.com");
            sendTo_email("mamontov@uihleb.ru");
            */
            h.m("Выполнено");
        }
        private void toolStripMenuItem59_Click(object sender, EventArgs e)
        {
            /*
             ikokonev@gmail.com
kokonev@list.ru
1086688@gmail.com
             */
            sendDataToEMAIL();
        }

        private void toolStripMenuItem61_Click(object sender, EventArgs e)
        {

        }

        private void toolStripMenuItem60_Click(object sender, EventArgs e)
        {
            functionService.connDB conDB = new functionService.connDB();
            conDB.setConn("serverExp", "zarpl");
            conDB.ShowGrid();

        }

        private void toolStripMenuItem60_Click_1(object sender, EventArgs e)
        {
            //functionService.connDB conDB = new functionService.connDB();
            userHK_grid.FormGRID ff = new userHK_grid.FormGRID("select * from city.sir_rd;","city", q.tk((int)param.server_1));
            ff.ShowDialog(); 
        }

        private void toolStripMenuItem62_Click(object sender, EventArgs e)
        {
            userHK_grid.FormGRID ff = new userHK_grid.FormGRID("select * from city.zakaz_rd;", "city", q.tk((int)param.server_1));
            ff.ShowDialog(); 
        }

        private void toolStripMenuItem63_Click(object sender, EventArgs e)
        {
            DataTable t = new DataTable(); t.ReadXml("PLP\\PLP_Connection.xml"); listAny f = new listAny(t); f.ShowDialog();

            if (f.IsOk == true)
            {
                q.put(param.server_1, f.sName);
                toolStripMenuItem63.Text = string.Concat("Активный сервер : ", f.sName);
                Application.Exit();
            }
        }

        private void toolStripMenuItem64_Click(object sender, EventArgs e)
        {
            int pers = functionService.DATECOD.codDATE_10913_from_DATETIME(q.tk((int)param.period_s_5));
            int perp = functionService.DATECOD.codDATE_10913_from_DATETIME(q.tk((int)param.period_p_6));
            string top = string.Concat("Сводный отчет с ", q.tk((int)param.period_s_5), " по ", q.tk((int)param.period_p_6));
            string itog = "Itog";
            userHK_grid.FormGRID fg = new userHK_grid.FormGRID(string.Concat("call `city`.`ct_period_zakaz`(", pers, " ,", perp, " );"), "city", q.tk((int)param.server_1), "GetSvodNDS", "GetSvodNDS", top, itog);
            fg.ShowDialog();
        }

        private void toolStripMenuItem65_Click(object sender, EventArgs e)
        {
            city7.lists.set.FormSETt  f =
                new city7.lists.set.FormSETt("o9","g5g5g5g","g55","gfdgg5"); 
            f.ShowDialog();
        }

        private void toolStripMenuItem66_Click(object sender, EventArgs e)
        {

        }

        private void toolStripMenuItem67_Click(object sender, EventArgs e)
        {
            //ostatkiCeh.ostatkiCeh ost = new ostatkiCeh.ostatkiCeh();
            //int pers = functionService.DATECOD.date_to_cod_int(q.tk((int)param.period_s_5));
            //int perp = functionService.DATECOD.date_to_cod_int(q.tk((int)param.period_p_6));
            //string serv = q.tk((int)param.server_1);
            //ost.GetPrihCeh(pers, perp, serv);

        }

        private void toolStripMenuItem68_Click(object sender, EventArgs e)
        {
            //ostatkiCeh.ostatkiCeh ost = new ostatkiCeh.ostatkiCeh();
            //int pers = functionService.DATECOD.date_to_cod_int(q.tk((int)param.period_s_5));
            //int perp = functionService.DATECOD.date_to_cod_int(q.tk((int)param.period_p_6));
            //string serv = q.tk((int)param.server_1);
            //ost.GetRasCeh(pers, perp, serv);
        }

        private void toolStripMenuItem69_Click(object sender, EventArgs e)
        {
            ostatkiCeh.ostatkiCeh ost = new ostatkiCeh.ostatkiCeh();
            int pers = functionService.DATECOD.date_to_cod_int(q.tk((int)param.period_s_5));
            int perp = functionService.DATECOD.date_to_cod_int(q.tk((int)param.period_p_6));
            string serv = q.tk((int)param.server_1);
            ost.GetOstCeh(pers, perp, serv);
        }

        private void toolStripMenuItem70_Click(object sender, EventArgs e)
        {

        }

        private void toolStripMenuItem71_Click(object sender, EventArgs e)
        {
            int db = functionService.DATECOD.date_to_cod_int(q.tk((int)param.period_s_5));
            int de = functionService.DATECOD.date_to_cod_int(q.tk((int)param.period_p_6));

            HK.City.CityKafeSir.ShowOstOnCityPer(db, de);
        }

        private void toolStripMenuItem72_Click(object sender, EventArgs e)
        {
            int db = functionService.DATECOD.date_to_cod_int(q.tk((int)param.period_s_5));
            int de = functionService.DATECOD.date_to_cod_int(q.tk((int)param.period_p_6));

            HK.City.CityKafeSir.ShowPrihRawOnCityAll(db, de);
        }

        private void toolStripMenuItem73_Click(object sender, EventArgs e)
        {
            int db = functionService.DATECOD.date_to_cod_int(q.tk((int)param.period_s_5));
            int de = functionService.DATECOD.date_to_cod_int(q.tk((int)param.period_p_6));

            HK.City.CityKafeSir.ShowPrihRawOnCityDay(db, de);
        }

        private void toolStripMenuItem74_Click(object sender, EventArgs e)
        {
            int db = functionService.DATECOD.date_to_cod_int(q.tk((int)param.day_work_7));
            int de = functionService.DATECOD.date_to_cod_int(q.tk((int)param.day_work_7));

            HK.City.CityKafeSir.ShowOstOnCityPer(db, de);
        }

        private void toolStripMenuItem77_Click(object sender, EventArgs e)
        {
            int db = functionService.DATECOD.date_to_cod_int(q.tk((int)param.period_s_5));
            int de = functionService.DATECOD.date_to_cod_int(q.tk((int)param.period_p_6));

            HK.City.CityKafeSir.ShowOstOnCityPer(db, de);
        }

        private void toolStripMenuItem78_Click(object sender, EventArgs e)
        {
            int db = functionService.DATECOD.date_to_cod_int(q.tk((int)param.period_s_5));
            int de = functionService.DATECOD.date_to_cod_int(q.tk((int)param.period_p_6));

            HK.City.CityKafeSir.ShowPrihRawOnCityAll(db, de);
        }

        private void toolStripMenuItem79_Click(object sender, EventArgs e)
        {
            int db = functionService.DATECOD.date_to_cod_int(q.tk((int)param.period_s_5));
            int de = functionService.DATECOD.date_to_cod_int(q.tk((int)param.period_p_6));

            HK.City.CityKafeSir.ShowRashRawOnCityAll(db, de);
        }

        private void toolStripMenuItem81_Click(object sender, EventArgs e)
        {
            int db = functionService.DATECOD.date_to_cod_int(q.tk((int)param.period_s_5));
            int de = functionService.DATECOD.date_to_cod_int(q.tk((int)param.period_p_6));

            HK.City.CityKafeSir.ShowRashTovOnCityAll(db, de);
        }

        private void toolStripMenuItem88_Click(object sender, EventArgs e)
        {
            int db = functionService.DATECOD.date_to_cod_int(q.tk((int)param.period_s_5));
            int de = functionService.DATECOD.date_to_cod_int(q.tk((int)param.period_p_6));

            HK.City.CityKafeSir.ShowPrihRawOnCityDay(db, de);
        }

        private void toolStripMenuItem89_Click(object sender, EventArgs e)
        {
            int db = functionService.DATECOD.date_to_cod_int(q.tk((int)param.period_s_5));
            int de = functionService.DATECOD.date_to_cod_int(q.tk((int)param.period_p_6));

            HK.City.CityKafeSir.ShowPrihRawOnCityCodd(db, de);
        }

        private void toolStripMenuItem84_Click(object sender, EventArgs e)
        {
            int db = functionService.DATECOD.date_to_cod_int(q.tk((int)param.period_s_5));
            int de = functionService.DATECOD.date_to_cod_int(q.tk((int)param.period_p_6));

            HK.City.CityKafeSir.ShowRashRawTovOnCityAll(db, de);
        }

        private void toolStripMenuItem85_Click(object sender, EventArgs e)
        {
            int db = functionService.DATECOD.date_to_cod_int(q.tk((int)param.period_s_5));
            int de = functionService.DATECOD.date_to_cod_int(q.tk((int)param.period_p_6));

            HK.City.CityKafeSir.ShowRashRawTovOnCityDay(db, de);
        }

        private void toolStripMenuItem86_Click(object sender, EventArgs e)
        {
            int db = functionService.DATECOD.date_to_cod_int(q.tk((int)param.period_s_5));
            int de = functionService.DATECOD.date_to_cod_int(q.tk((int)param.period_p_6));

            HK.City.CityKafeSir.ShowRashTovRawOnCityAll(db, de);
        }

        private void toolStripMenuItem87_Click(object sender, EventArgs e)
        {
            int db = functionService.DATECOD.date_to_cod_int(q.tk((int)param.period_s_5));
            int de = functionService.DATECOD.date_to_cod_int(q.tk((int)param.period_p_6));

            HK.City.CityKafeSir.ShowRashTovRawOnCityDay(db, de);
        }

        private void toolStripMenuItem69_Click_1(object sender, EventArgs e)
        {
            //ostatkiCeh.ostatkiCeh ost = new ostatkiCeh.ostatkiCeh();
            //int pers = functionService.DATECOD.date_to_cod_int(q.tk((int)param.day_work_7));
            //string serv = q.tk((int)param.server_1);
            //ost.GetPrihCeh(pers, pers, serv);

        }

        private void toolStripMenuItem90_Click(object sender, EventArgs e)
        {
            //ostatkiCeh.ostatkiCeh ost = new ostatkiCeh.ostatkiCeh();
            //int pers = functionService.DATECOD.date_to_cod_int(q.tk((int)param.day_work_7));
            //string serv = q.tk((int)param.server_1);
            //ost.GetRasCeh(pers, pers, serv);

        }

        private void toolStripMenuItem91_Click(object sender, EventArgs e)
        {
            ostatkiCeh.ostatkiCeh ost = new ostatkiCeh.ostatkiCeh();
            int pers = functionService.DATECOD.date_to_cod_int(q.tk((int)param.day_work_7));
            string serv = q.tk((int)param.server_1);
            ost.GetOstCeh(pers, pers, serv);
        }

        private void toolStripMenuItem92_Click(object sender, EventArgs e)
        {
            ostatkiCeh.ostatkiCeh ost = new ostatkiCeh.ostatkiCeh();
            int pers = functionService.DATECOD.date_to_cod_int(q.tk((int)param.period_s_5));
            int perp = functionService.DATECOD.date_to_cod_int(q.tk((int)param.period_p_6));
            string serv = q.tk((int)param.server_1);
            ost.GetPrihCeh(pers, perp, serv);

        }

        private void toolStripMenuItem93_Click(object sender, EventArgs e)
        {
            ostatkiCeh.ostatkiCeh ost = new ostatkiCeh.ostatkiCeh();
            int pers = functionService.DATECOD.date_to_cod_int(q.tk((int)param.period_s_5));
            int perp = functionService.DATECOD.date_to_cod_int(q.tk((int)param.period_p_6));
            string serv = q.tk((int)param.server_1);
            ost.GetRasCeh(pers, perp, serv);
        }

        private void toolStripMenuItem94_Click(object sender, EventArgs e)
        {
            ostatkiCeh.ostatkiCeh ost = new ostatkiCeh.ostatkiCeh();
            int pers = functionService.DATECOD.date_to_cod_int(q.tk((int)param.period_s_5));
            int perp = functionService.DATECOD.date_to_cod_int(q.tk((int)param.period_p_6));
            string serv = q.tk((int)param.server_1);
            ost.GetOstCeh(pers, perp, serv);
        }

        private void toolStripMenuItem95_Click(object sender, EventArgs e)
        {
            ostatkiCeh.ostatkiCeh ost = new ostatkiCeh.ostatkiCeh();
            int pers = functionService.DATECOD.date_to_cod_int(q.tk((int)param.period_s_5));
            int perp = functionService.DATECOD.date_to_cod_int(q.tk((int)param.period_p_6));
            string serv = q.tk((int)param.server_1);
            ost.GetVipuskCeh(pers, perp, serv);
        }

        private void toolStripMenuItem96_Click(object sender, EventArgs e)
        {
        }

        private void toolStripMenuItem97_Click(object sender, EventArgs e)
        {

        }

        private void toolStripMenuItem97_Click_1(object sender, EventArgs e)
        {
            try
            {
                q = new functionService.prm_city();
                functionService.connDB conDB = new functionService.connDB();
                conDB.setConn(q.tk(param.server_1), "city_net");
                conDB.co();
                conDB.UpdateData("CALL city_net.remote_LoadDataFromCity();");
                conDB.UpdateData("CALL city_net.remote_LoadDataToCity();");
                conDB.cc();
                MessageBox.Show("Обновление прошло успешно.");
            }
            catch
            {
                MessageBox.Show("Ошибка! Не удалось обновиться.");
            }
        }

        private void toolStripMenuItem98_Click(object sender, EventArgs e)
        {
            q = new functionService.prm_city();
            functionService.connDB cnDB = new functionService.connDB();
            cnDB.setConn(q.tk(param.server_1), "city");
            cnDB.co();
            cnDB.UpdateData("CALL data_crtCityTovTbl(" + functionService.DATECOD.date_to_cod_int(q.tk(param.period_s_5)) + "," + functionService.DATECOD.date_to_cod_int(q.tk(param.period_p_6)) + ");");
            DataTable tdb = cnDB.selectAny("SELECT * FROM tov_listtovsootvskladcity skl WHERE skl.ctCity = 0;");
            cnDB.cc();
            if (tdb.Rows.Count > 0)
            {
                MessageBox.Show("Внимание! Присутствует несгруппированное сырье.");
            }
            ostatkiCeh.ostatkiCeh ost = new ostatkiCeh.ostatkiCeh();
            string serv = q.tk((int)param.server_1);
            ost.SetGroupSir(serv);


        }

        private void toolStripMenuItem99_Click(object sender, EventArgs e)
        {
            ostatkiCeh.ostatkiCeh ost = new ostatkiCeh.ostatkiCeh();
            //int pers = functionService.DATECOD.date_to_cod_int(q.tk((int)param.day_work_7));
            string serv = q.tk((int)param.server_1);
            //int cod_sc = 227;
            functionService.connDB cnDB = new functionService.connDB();
            cnDB.setConn(serv, "city");
            cnDB.co();
            DataTable prod = cnDB.selectAny(string.Concat("SELECT ",
                "cod AS cod, name AS name ",
                "FROM list_sc l ORDER BY name;"));
            cnDB.cc();
            listAny la = new listAny(prod); la.ShowDialog();
            if (la.IsOk)
            {
                int cod_sc = Convert.ToInt32(la.sCod);
                ost.GetListRecept(cod_sc, serv);
            }

        }

        private void toolStripMenuItem100_Click(object sender, EventArgs e)
        {

        }

        private void toolStripMenuItem100_Click_1(object sender, EventArgs e)
        {
        }

        private void toolStripMenuItem101_Click(object sender, EventArgs e)
        {
           
        }

        private void toolStripMenuItem76_Click(object sender, EventArgs e)
        {
            int db = functionService.DATECOD.date_to_cod_int(q.tk((int)param.day_work_7));
            int de = functionService.DATECOD.date_to_cod_int(q.tk((int)param.day_work_7));

            HK.City.CityKafeSir.ShowRashRawOnCityAll(db, de);
        }

        private void toolStripMenuItem82_Click(object sender, EventArgs e)
        {
            int db = functionService.DATECOD.date_to_cod_int(q.tk((int)param.day_work_7));
            int de = functionService.DATECOD.date_to_cod_int(q.tk((int)param.day_work_7));

            HK.City.CityKafeSir.ShowRashTovOnCityAll(db, de);
        }

        private void toolStripMenuItem75_Click(object sender, EventArgs e)
        {
            int db = functionService.DATECOD.date_to_cod_int(q.tk((int)param.day_work_7));
            int de = functionService.DATECOD.date_to_cod_int(q.tk((int)param.day_work_7));

            HK.City.CityKafeSir.ShowPrihRawOnCityAll(db, de);
        }

        private void toolStripMenuItem83_Click(object sender, EventArgs e)
        {
            int db = functionService.DATECOD.date_to_cod_int(q.tk((int)param.day_work_7));
            int de = functionService.DATECOD.date_to_cod_int(q.tk((int)param.day_work_7));

            HK.City.CityKafeSir.ShowVozvrRawOnCityAll(db, de);
        }

        private void toolStripMenuItem80_Click(object sender, EventArgs e)
        {
            int db = functionService.DATECOD.date_to_cod_int(q.tk((int)param.period_s_5));
            int de = functionService.DATECOD.date_to_cod_int(q.tk((int)param.period_p_6));

            HK.City.CityKafeSir.ShowVozvrRawOnCityAll(db, de);
        }

        private void toolStripMenuItem102_Click(object sender, EventArgs e)
        {
            //ostatkiCeh.ostatkiCeh ost = new ostatkiCeh.ostatkiCeh();
            //int pers = functionService.DATECOD.date_to_cod_int(q.tk((int)param.day_work_7));
            //string serv = q.tk((int)param.server_1);
            //ost.proba1(pers, pers, serv);

        }

        private void toolStripMenuItem103_Click(object sender, EventArgs e)
        {
            ostatkiCeh.ostatkiCeh ost = new ostatkiCeh.ostatkiCeh();
            int pers = functionService.DATECOD.date_to_cod_int(q.tk((int)param.period_s_5));
            int perp = functionService.DATECOD.date_to_cod_int(q.tk((int)param.period_p_6));
            string serv = q.tk((int)param.server_1);
            ost.GetRashProdSirCeh(pers, perp, serv);
        }

        private void toolStripMenuItem104_Click(object sender, EventArgs e)
        {
            ostatkiCeh.ostatkiCeh ost = new ostatkiCeh.ostatkiCeh();
            int pers = functionService.DATECOD.date_to_cod_int(q.tk((int)param.period_s_5));
            int perp = functionService.DATECOD.date_to_cod_int(q.tk((int)param.period_p_6));
            string serv = q.tk((int)param.server_1);
            ost.GetRashSirProdCeh(pers, perp, serv);
        }

        private void toolStripMenuItem105_Click(object sender, EventArgs e)
        {
            MySqlConnection conn = new MySqlConnection("server=serverExp;user id=muser; password=; " +
                                                            "database=wwm; pooling=false; charset=utf8");
            conn.Open();
            //MySqlCommand cm = new MySqlCommand("SELECT codVod, codZona, prim FROM wwm.liststavka LIMIT 3000", conn);
            MySqlCommand cm = new MySqlCommand("CALL srfnc.`util_getGroupTableGr1`('SELECT * FROM test.testtblgroup', '0, grField, 0, 0, 0');", conn);
            MySqlDataReader dr;
            dr = cm.ExecuteReader();
            DataTable dt = new DataTable();
            dt.Load(dr);

            HK.Reports.Report r = new HK.Reports.Report(
                "testReport", dt, 
                "Заголовок отчета", 
                "Итог отчета", 
                "100;100;100;100;100;100", 
                "Кол1;Кол2;Кол3;Кол4;Кол5;Кол6",
                "c;l;l;l;l;l");
            r.ShowReport();
        }

        private void listView1_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void toolStripMenuItem117_Click(object sender, EventArgs e)
        {
            int db = functionService.DATECOD.date_to_cod_int(q.tk((int)param.period_s_5));
            int de = functionService.DATECOD.date_to_cod_int(q.tk((int)param.period_p_6));

            HK.City.CityMagTov.ShowVozvrMag(db, de);
        }

        private void toolStripMenuItem114_Click(object sender, EventArgs e)
        {
            int db = functionService.DATECOD.date_to_cod_int(q.tk((int)param.period_s_5));
            int de = functionService.DATECOD.date_to_cod_int(q.tk((int)param.period_p_6));

            HK.City.CityMagTov.ShowAllOstMag(db, de);
        }

        private void toolStripMenuItem115_Click(object sender, EventArgs e)
        {
            int db = functionService.DATECOD.date_to_cod_int(q.tk((int)param.period_s_5));
            int de = functionService.DATECOD.date_to_cod_int(q.tk((int)param.period_p_6));

            HK.City.CityMagTov.ShowPrihMag(db, de);
        }

        private void toolStripMenuItem116_Click(object sender, EventArgs e)
        {
            int db = functionService.DATECOD.date_to_cod_int(q.tk((int)param.period_s_5));
            int de = functionService.DATECOD.date_to_cod_int(q.tk((int)param.period_p_6));

            HK.City.CityMagTov.ShowRashMag(db, de);
        }

        private void toolStripMenuItem111_Click(object sender, EventArgs e)
        {
            int db = functionService.DATECOD.date_to_cod_int(q.tk((int)param.day_work_7));
            int de = functionService.DATECOD.date_to_cod_int(q.tk((int)param.day_work_7));

            HK.City.CityMagTov.ShowPrihMag(db, de);
        }

        private void toolStripMenuItem112_Click(object sender, EventArgs e)
        {
            int db = functionService.DATECOD.date_to_cod_int(q.tk((int)param.day_work_7));
            int de = functionService.DATECOD.date_to_cod_int(q.tk((int)param.day_work_7));

            HK.City.CityMagTov.ShowRashMag(db, de);
        }

        private void toolStripMenuItem113_Click(object sender, EventArgs e)
        {
            int db = functionService.DATECOD.date_to_cod_int(q.tk((int)param.day_work_7));
            int de = functionService.DATECOD.date_to_cod_int(q.tk((int)param.day_work_7));

            HK.City.CityMagTov.ShowVozvrMag(db, de);
        }

        private void toolStripMenuItem110_Click(object sender, EventArgs e)
        {
            int db = functionService.DATECOD.date_to_cod_int(q.tk((int)param.day_work_7));
            int de = functionService.DATECOD.date_to_cod_int(q.tk((int)param.day_work_7));

            HK.City.CityMagTov.ShowOstMag(db, de);
        }

        private void toolStripMenuItem69_Click_2(object sender, EventArgs e)
        {

        }

        private void toolStripMenuItem69_Click_3(object sender, EventArgs e)
        {
            ostatkiCeh.ostatkiCeh ost = new ostatkiCeh.ostatkiCeh();
            int pers = functionService.DATECOD.date_to_cod_int(q.tk((int)param.day_work_7));
            string serv = q.tk((int)param.server_1);
            ost.ResetOstFakt(pers, pers, serv);
        }

        private void toolStripMenuItem90_Click_1(object sender, EventArgs e)
        {

        }

        private void toolStripMenuItem118_Click(object sender, EventArgs e)
        {
            ostatkiCeh.ostatkiCeh ost = new ostatkiCeh.ostatkiCeh();
            int pers = functionService.DATECOD.date_to_cod_int(q.tk((int)param.period_s_5));
            int perp = functionService.DATECOD.date_to_cod_int(q.tk((int)param.period_p_6));
            string serv = q.tk((int)param.server_1);
            ost.GetOstCehSmall(pers, perp, serv);
        }

        private void toolStripMenuItem34_Click_2(object sender, EventArgs e)
        {
            FormDoc f = new FormDoc(); f.ShowDialog();
        }
        private void addPF_TehSir()
        {
            DataTable dt = q.selectAny("call `city`.`FOR_add_to__list_tehsir_z__from__list_sc` ()");
            int ic = dt.Rows.Count;
            int iomax = h.i(q.selectScalar("select max(cod)+1 from list_tehsir_z where cod<888;"));
            int i = 0;
            foreach (DataRow r in dt.Rows)
            {
                q.UpdateData
                   (
                   string.Concat
                       (
                         "insert into list_tehsir_z(cod, name, izm) values (", iomax + i, ",'", r[1], "', 'гр');"
                       )
                   );
                q.UpdateData
                   (
                   string.Concat
                       (
                         "call `city`.`rz_update_list_sc_tehsir_z`(",
                        r[0], " , ",
                        iomax + i, ");"
                       )
                   );
                i++;
            }
        }
        private void toolStripMenuItem100_Click_2(object sender, EventArgs e)
        {
           
        }

        private void toolStripMenuItem119_Click(object sender, EventArgs e)
        {
           
        }

        private void toolStripMenuItem120_Click(object sender, EventArgs e)
        {
           // city7.FormGE g = new city7.FormGE(); g.ShowDialog();
           // h.m(h.aa( g.t.Rows[0][0], g.t.Rows[0][1]));
            
        }

        private void toolStripMenuItem121_Click(object sender, EventArgs e)
        {



        }

        private void toolStripMenuItem122_Click(object sender, EventArgs e)
        {
            string sm = SMENA;
            string cod203 = sm.Substring(0, 3);
            string day01 = sm.Substring(2, 2);
            string sql = string.Concat("CALL nostPrihRashOst_rashod2(", cod203, ",", day01, ", 1);");
            userHK_grid.FormGRID f = new userHK_grid.FormGRID(sql,"city", "localhost");
            f.ShowDialog();
        }

        private void toolStripMenuItem123_Click(object sender, EventArgs e)
        {
            string sm = SMENA;
            string cod203 = sm.Substring(0,3);
            string day01 = sm.Substring(2,2);

            string sql = 
               string.Concat( "call `city`.`ost_workDay`(",cod203 ,",",  day01 ,",",day01 ,", 1);");
            userHK_grid.FormGRID f =
                new userHK_grid.FormGRID(sql, "city", "localhost");

            f.ShowDialog();
        }

        private void toolStripMenuItem124_Click(object sender, EventArgs e)
        {
            string sm = SMENA;
            string cod203 = sm.Substring(0, 3);
           // string day01 = sm.Substring(2, 2);

            int ps = Convert.ToDateTime(q.tk(param.period_s_5)).Day ,
                pp = Convert.ToDateTime(q.tk(param.period_p_6)).Day;
            /*`city`.`select_all_prihToZeh` (
year_monthCurrent_203 int,
dayB int, dayE int,
LOOK_1_DONTLOOK_0 INT)*/
            string sql =
               string.Concat("call `city`.`select_all_prihToZeh`(", cod203, ",", ps, ",", pp, ", 1);");
            userHK_grid.FormGRID f =
                new userHK_grid.FormGRID(sql, "city", "localhost");

            f.ShowDialog();
        }

        private void toolStripMenuItem128_Click(object sender, EventArgs e)
        {
       
        }

        private void toolStripMenuItem127_Click(object sender, EventArgs e)
        {

        }

        private void perctnonullToolStripMenuItem_Click(object sender, EventArgs e)
        {
            /*
        * `city`.`nostPrihRashOst_rashod2`(
year_monthCurrent_203 int, dayOst int, LOOK_1_DONTLOOK_0 int)
        */

            string sm = SMENA;
            string cod203 = sm.Substring(0, 3);
            string day01 = sm.Substring(2, 2);


            /*`city`.`select_all_prihToZeh` (
year_monthCurrent_203 int,
dayB int, dayE int,
LOOK_1_DONTLOOK_0 INT)*/
            string sql =
               string.Concat("call `city`.`nostPrihRashOst_rashod2`(", cod203, ",", day01, ", 2);");
            userHK_grid.FormGRID f =
                new userHK_grid.FormGRID(sql, "city", "localhost");

            f.ShowDialog();
        }

        private void perctnulToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string sm = SMENA;
            string cod203 = sm.Substring(0, 3);
            string day01 = sm.Substring(2, 2);


            /*`city`.`select_all_prihToZeh` (
year_monthCurrent_203 int,
dayB int, dayE int,
LOOK_1_DONTLOOK_0 INT)*/
            string sql =
               string.Concat("call `city`.`nostPrihRashOst_rashod2`(", cod203, ",", day01, ", 3);");
            userHK_grid.FormGRID f =
                new userHK_grid.FormGRID(sql, "city", "localhost");

            f.ShowDialog();
        }

        private void pnonullToolStripMenuItem_Click(object sender, EventArgs e)
        {
            /*`city`.`ost_workDay_ras`(
year_monthCurrent_203 int,
dayB int, dayE int,
LOOK_1_DONTLOOK_0 INT)*/

            string sm = SMENA;
            string cod203 = sm.Substring(0, 3);

            int ps = Convert.ToDateTime(q.tk(param.period_s_5)).Day,
                pp = Convert.ToDateTime(q.tk(param.period_p_6)).Day;

            string sql =
               string.Concat("call `city`.`ost_workDay_ras`(", cod203, ",", ps, ",", pp, ", 2);");
            userHK_grid.FormGRID f =
                new userHK_grid.FormGRID(sql, "city", "localhost");

            f.ShowDialog();

        }

        private void pnullToolStripMenuItem_Click(object sender, EventArgs e)
        {
            /*`city`.`ost_workDay_ras`(
year_monthCurrent_203 int,
dayB int, dayE int,
LOOK_1_DONTLOOK_0 INT)*/

            string sm = SMENA;
            string cod203 = sm.Substring(0, 3);

            int ps = Convert.ToDateTime(q.tk(param.period_s_5)).Day,
                pp = Convert.ToDateTime(q.tk(param.period_p_6)).Day;

            string sql =
               string.Concat("call `city`.`ost_workDay_ras`(", cod203,
               ",", ps, 
               ",", pp,
               ", 3);");
            userHK_grid.FormGRID f =
                new userHK_grid.FormGRID(sql, "city", "localhost");

            f.ShowDialog();
        }

        private void toolStripMenuItem126_Click(object sender, EventArgs e)
        {
            /*`call `city`.`select_all_rashodFromZeh` (203,1,3);*/

            string sm = SMENA;
            string cod203 = sm.Substring(0, 3);

            int ps = Convert.ToDateTime(q.tk(param.period_s_5)).Day,
                pp = Convert.ToDateTime(q.tk(param.period_p_6)).Day;

            string sql =
               string.Concat("call `city`.`select_all_rashodFromZeh`(", cod203, ",", ps, ",", pp, ");");
            userHK_grid.FormGRID f =
                new userHK_grid.FormGRID(sql, "city", "localhost");

            f.ShowDialog();
        }

        private void toolStripMenuItem131_Click(object sender, EventArgs e)
        {
            listAnyEdit f = new listAnyEdit(editParam_pr, "city", city.listtov, invert(bor));
            f.ShowDialog();
        }
        private void selectProZeh()
        {
            listAnyEdit f = new listAnyEdit
                          (editParam_sht_zeh, "city", city.list_sc, "cod < 3000 And cod <> 888",
                          f_add_Poluf, f_del_Poluf, f_edit_Poluf);
            f.ShowDialog();
        }
        private void toolStripMenuItem130_Click(object sender, EventArgs e)
        {
            selectProZeh();
        }

        private void toolStripMenuItem129_Click(object sender, EventArgs e)
        {
            listAnyEdit f =
               new listAnyEdit(editParam_tehsir, "city", "list_tehsir_z", "cod<3000 and cod<>888");
            f.ShowDialog();
        }

        private void toolStripMenuItem20_Click_2(object sender, EventArgs e)
        {

        }

        private void toolStripMenuItem100_Click_3(object sender, EventArgs e)
        {
            listAnyEdit f = new listAnyEdit("lists", "org_listorg", true);
            f.ShowDialog();
        }

        private void toolStripMenuItem101_Click_1(object sender, EventArgs e)
        {

            listAnyEdit f = new listAnyEdit("city", "sir_listorg", false);
            f.ShowDialog();
        }

        private void toolStripMenuItem132_Click(object sender, EventArgs e)
        {
            listAnyEdit f = new listAnyEdit(editParam_sotr, "lists", city.sotr, invert(bor));
            f.ShowDialog();
        }

        private void toolStripMenuItem133_Click(object sender, EventArgs e)
        {
            listAnyEdit f = new listAnyEdit("city", city.listtable, false);
            f.ShowDialog();
        }

        private void toolStripMenuItem19_Click_2(object sender, EventArgs e)
        {

        }

        private void toolStripMenuItem23_Click_1(object sender, EventArgs e)
        {

            city7.FormPFPF f = new city7.FormPFPF(); f.ShowDialog();
        }

        private void toolStripMenuItem25_Click_2(object sender, EventArgs e)
        {
            try
            {
                ////listAnyEdit f = new listAnyEdit("city", city.list_sc, false); f.ShowDialog();
                // listAnyEdit f = new listAnyEdit(editParam_SIR_sc, "city", city.list_sc, invert(bor));
                // f.ShowDialog();

                // city7.FormSirTehSir f = new city7.FormSirTehSir(); f.ShowDialog();
                                              //select_sir_tehSir
                city7.FormSirTehSir f = new city7.FormSirTehSir(); f.ShowDialog();
                q.put(64, h.TRUFAL(vv.sirTehSir.trueMemo));
            }
            catch { }
        }

        private void toolStripMenuItem27_Click_1(object sender, EventArgs e)
        {
            city7.FormRezList f = new city7.FormRezList(); f.ShowDialog();
        }

        private void toolStripMenuItem58_Click_1(object sender, EventArgs e)
        {
            city7.FormAkt f = new city7.FormAkt(); f.ShowDialog();
        }

        private void toolStripMenuItem121_Click_1(object sender, EventArgs e)
        {
            city7.FormDocLook f = new city7.FormDocLook((int)city7.opro.list_doc_month); f.ShowDialog();
        }

        private void toolStripMenuItem122_Click_1(object sender, EventArgs e)
        {

        }
        private void lookDoc()
        {
            city7.FormDocLook f = new city7.FormDocLook((int)city7.opro.list_doc_month); f.ShowDialog();

        }

        private void toolStripMenuItem135_Click(object sender, EventArgs e)
        {
            city7.FormAkt f = new city7.FormAkt(); f.ShowDialog();
        }

        private void toolStripMenuItem119_Click_1(object sender, EventArgs e)
        {
           
        }

        private void toolStripMenuItem134_Click(object sender, EventArgs e)
        {
            

        }

        private void toolStripMenuItem136_Click(object sender, EventArgs e)
        {
           
        }

        private void toolStripMenuItem137_Click(object sender, EventArgs e)
        {
        }

        private void toolStripMenuItem138_Click(object sender, EventArgs e)
        {
            city7.FormDocLook f = new city7.FormDocLook((int)city7.opro.lookDoc_RASHODnr); f.ShowDialog();
        }

        private void toolStripMenuItem139_Click(object sender, EventArgs e)
        {
           
        }

        private void заПериодToolStripMenuItem_Click(object sender, EventArgs e)
        {
            /*
            * call `city`.`look_ras_td_203`(203,
1, 28, 888,   14);
            */
            city7.FormDocLook f = new city7.FormDocLook((int)city7.opro.look_SirPer); f.ShowDialog();
        }

        private void toolStripMenuItem141_Click(object sender, EventArgs e)
        {
            city7.FormDocLook f = new city7.FormDocLook((int)city7.opro.look_SirPer_Before); f.ShowDialog();

        }

        private void toolStripMenuItem137_Click_1(object sender, EventArgs e)
        {
            
        }

        private void расходToolStripMenuItem_Click(object sender, EventArgs e)
        {
           
        }

        private void toolStripMenuItem119_Click_2(object sender, EventArgs e)
        {
            city7.FormDocLook f = new city7.FormDocLook((int)city7.opro.look_r4_rdtd_prod); f.ShowDialog();
        }

        private void toolStripMenuItem134_Click_1(object sender, EventArgs e)
        {
            city7.FormDocLook f = new city7.FormDocLook((int)city7.opro.look_ost_workDay_s2_1__param2 ); f.ShowDialog();
        }

        private void toolStripMenuItem138_Click_1(object sender, EventArgs e)
        {
            city7.FormDocLook f = new city7.FormDocLook((int)city7.opro.lookDoc_PRIHOD); f.ShowDialog();
        }

        private void toolStripMenuItem143_Click(object sender, EventArgs e)
        {
            city7.opro sopro;

            if (MessageBox.Show("Расход подробно-да, Расход по дням-нет", "Выбор", MessageBoxButtons.YesNo) == DialogResult.Yes)
            {
                sopro = city7.opro.lookDoc_RASHOD;
            }
            else
            {
                sopro = city7.opro.lookDoc_RASHODdays;
            }

            city7.FormDocLook f = new city7.FormDocLook((int)sopro); f.ShowDialog();
        }

        private void toolStripMenuItem33_Click_2(object sender, EventArgs e)
        {
            city7.table.FormTable f = new city7.table.FormTable((int)city7.table.modeLoad.mainListSC);
            f.ShowDialog();
        }

        private void toolStripMenuItem142_Click(object sender, EventArgs e)
        {
            vv.ost_create.year = q.tk_int_year_fromDate(param.period_p_6);
            vv.ost_create.month = q.tk_int_month_fromDate(param.period_p_6);
            city7.FormAkt f = new city7.FormAkt(); f.ShowDialog();
        }

        private void toolStripMenuItem136_Click_1(object sender, EventArgs e)
        {

           // da.yearCod();
            string sql_dml = "";
            vv.ost_create.year = q.tk_int_year_fromDate(param.period_s_5);
            vv.ost_create.month = q.tk_int_month_fromDate(param.period_s_5 );

            if (MessageBox.Show(
                "Переходящие остатки за период следующий за указанным будут удалены и СФОРМИРОВАННЫ новые по документам текущего месяца",
                "Выбор",
                MessageBoxButtons.OKCancel) == DialogResult.OK)
            {
                pereschetOst();
              sql_dml=  string.Concat("CALL `ost_perenos_NextMonth`(",
                  vv.ost_create.codd_203011900, ",",
                  vv.ost_create.dd_20110301,
                  ",1);"); //h.m(sql_dml);

              DataTable dt = q.selectAny(sql_dml);

                h.m("Остатки сформированы");
                q.sh(dt);
            }
           // h.m(vv.ost_create.codd_203011900, " ", vv.ost_create.month, " ",vv.ost_create.year, "Остатки сформированы");
    

        }
        void pereschetOst()
        {
            string sds = q.tk(ETALON.param.period_s_5),
                sdp = q.tk(ETALON.param.period_p_6),
                ds = Convert.ToDateTime(sds).Day.ToString(),
                dp = Convert.ToDateTime(sdp).Day.ToString(),
                sm = q.tk(ETALON.param.kafe_smena_42).Substring(0, 3);
            DataTable dts;
            //ost_workDay_s2_1
           //// int ii = 0;
           //// if (MessageBox.Show("Пересчитать остатки", "Выбор",
           ////     MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { ii = 1; }
           //// else { ii = 0; }

           //// DataTable dts = q.selectAny(string.Concat("call `city`.`ost_workDay_s2_1_akt` (", sm, ", ", ds, ",", dp, ", 3, ", ii, ");"));
           ////// q.sh( dts);

            if (MessageBox.Show("Пересчитать остатки", "Выбор",
               MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                dts = q.selectAny(string.Concat("call `city`.`ost_workDay_s2_1_akt` (", sm, ", ", ds, ",", dp, ", 3, 1);"));
            }
            else
            {
                dts = q.selectAny(string.Concat("SELECT * FROM citytemp", Month01, ".owd_ost_wd_filt ORDER BY name;"));
            }



        }

        private void toolStripMenuItem137_Click_2(object sender, EventArgs e)
        {
            for (int i = 1; i < 10; i++)
            {
                createTablesOstForYear(i);
            }
            m(300);
        }
        private void createTablesOstForYear(int codYear)
        {
            int y = codYear ;
            int ym=0;
            string sql_dml="-", sql_drop="-";
            for (int m = 1; m < 13; m++)
            {
                ym = y*100+m;
                sql_drop = string.Concat("DROP TABLE IF EXISTS citytemp.owd_ost_wd_", ym ,";");
                sql_dml = string.Concat(
                    "create table citytemp.owd_ost_wd_", 
                    ym ,
                    " select * from citytemp.owd_ost_wd_2010;");
                q.UpdateData(sql_drop); q.UpdateData(sql_dml);
            }
        }

        private void toolStripMenuItem139_Click_1(object sender, EventArgs e)
        {
            city7.FormDocLook f = new city7.FormDocLook((int)city7.opro.lookAvgPr); f.ShowDialog();
        }

        private void toolStripMenuItem145_Click(object sender, EventArgs e)
        {
            createTableAVGP(); createTableAVGP2();
        }
        private void createTableAVGP()
        {
            string sm = q.tk(ETALON.param.kafe_smena_42).Substring(0, 3);
            string sql_dml = string.Concat("call `city`.`avgPR2`(", sm, ");");
            q.UpdateData(sql_dml);
            // создает таблицу средних цен sir_ts_pr
            h.m("Завершен расчет средних цен");
        }
        private void createTableAVGP2()
        {
            string sm = q.tk(ETALON.param.kafe_smena_42).Substring(0, 3);
            string sql_dml = string.Concat("call `city`.`avgPR222`(", sm, ");");
            q.UpdateData(sql_dml);
            h.m("Средние цены внесены в документы прихода");
        }
        private void setPrAkt()
        {
            string sm = q.tk(ETALON.param.kafe_smena_42).Substring(0, 3);

            q.UpdateData(prep_aktPr(sm));
            DataTable dt_codd = q.selectAny(select_coddAkt);
            DataTable dt_pr = q.selectAny(select_pr);
            updatePR(dt_pr);
            deleteAktFrom_sir_td_z(dt_codd);
            q.UpdateData(insertToTD0);
            q.UpdateData("call `hand_set123_sir_td_z`();");
            h.m("ok");

        }
        private string UPDATE_pr(object cto, object pro)
        {
            return string.Concat("UPDATE citytemp.avg_sir_td_z_AktNewPr SET pr=", pro, " WHERE ct = ", cto, ";"); 
        }
        private string select_coddAkt
        {
            get
            {
                return string.Concat("select codd from citytemp.avg_coddAkt;");
            }
        }
        private string select_pr
        {
            get
            {
                return string.Concat("select ct, pr from citytemp.skl_prAvg3;");
            }
        }
        private string prep_aktPr(object  smo)
        {
            return string.Concat("call `city`.`avgPr_prep_coddAkt` (",  smo,", 0);");
        }

        private void deleteAktFrom_sir_td_z(DataTable dt_coddo)
        {
            foreach (DataRow r in dt_coddo.Rows)
            {
                q.UpdateData(string.Concat("DELETE FROM sir_td_z WHERE codd = ", r[0], ";"));
            }
        }
        private void updatePR(DataTable dt_pro)
        {
            foreach (DataRow r in dt_pro.Rows)
            {
                q.UpdateData(UPDATE_pr(r[0], r[1].ToString().Replace(",",".")));
            }
        }
        private string  insertToTD0
        {
            get
            {
                return string.Concat("insert into city.sir_td_z(cod123,ct,pr,kol,numcod,codd,posm,crd,deb,ndSkl,kol2)",
                    " select 0 as cod123,ct,pr,kol,numcod,codd,posm,crd,deb,ndSkl,kol2",
                    " from citytemp.avg_sir_td_z_AktNewPr;");
            }
        }

        private void toolStripMenuItem146_Click(object sender, EventArgs e)
        {
            createTableAVGP2(); //setPrAkt();
        }

        private void toolStripMenuItem147_Click(object sender, EventArgs e)
        {
           /* city.avgPr_prep_coddAkt(year_monthCurrent_203 INT,
                                  LOOK_1_DONTLOOK_0     INT
                                  )
            */
            updateAVG_Pr();
            
            h.m("Выполнено");
        }
        private void updateAVG_Pr()
        {
            string sm = q.tk(ETALON.param.kafe_smena_42).Substring(0, 3);
            // CALL CITY.AVGP_create_table_avgPr(112, 0);
            q.UpdateData(string.Concat("call city.AVGP_create_table_avgPr(", sm, ", 0 )"));
            q.UpdateData(string.Concat("call city.avgPr_prep_coddAkt(", sm, ", 0 )"));
        }
        private void toolStripMenuItem148_Click(object sender, EventArgs e)
        {
            string sm = q.tk(ETALON.param.kafe_smena_42).Substring(0, 3);
            DataTable dt = q.selectAny(string.Concat("call city.select_avgPr(", sm, ");")); q.sh(dt);
        }

        private void toolStripMenuItem144_Click(object sender, EventArgs e)
        {

        }

        private void toolStripMenuItem149_Click(object sender, EventArgs e)
        {

        }

        private void toolStripMenuItem151_Click(object sender, EventArgs e)
        {

            /*vv.path_sklad_import =  "\\\\May\\c\\Work\\Sklad\\Skltabl\\Skl4117.mdb";
            string slokal = q.tk(63); // 1-local 0 -po seti
            if (slokal == "1") { vv.path_sklad_import = "c:\\Work\\donet\\Skl4117.mdb";}*/
            string sourseFileName = "\\\\May\\c\\Work\\Sklad\\Skltabl\\Skl4117.mdb";
            string destenFileName = "c:\\Work\\donet\\Skl4117.mdb";
            string[] sa = Directory.GetFiles("c:\\Work\\donet");
            bool IsHere = false;

            for (int j = 0; j < sa.Length; j++)
            {
                m(sa[j]);
                if (sa[j] == destenFileName) { IsHere = true; m(9000); break; }
            }




                try
                {
                    if (IsHere) File.Delete(destenFileName);
                    File.Copy(sourseFileName, destenFileName); h.m("Выполнено");
                    q.put(63,0); // po seti
                }
                catch
                {  h.m("Копирование не выполнено"); q.put(63, 1); // local
                }
        }
    }


    public struct COPY_PASTE
    {
        public static ListViewItem[] lva;   public static bool IsCopy = false;
    }
    class city
    {
       
       public const  string  etalon_folders = "etalon_folders",
            etalon_object = "etalon_object",
            listregular = "listregular",
            listtable = "listtable",
            listtov = "listtov",
            list_sc = "list_sc",
            listtov_folders = "listtov_folders",
            listtov_objects = "listtov_objects",
            rd = "rd", td = "td",
            sotr = "sot_listsot",
            listservers = "listservers",
            pro_listselect="pro_listselect",
            pro_listselect__razr = "Разработчик (1)",
            pro_listselect__user = "Пользователь (2)",
            pro_listselect__serverKIN = "Сервер КИН",
            pro_listselect__serverEXP = "Сервер ЭКСП";
        //public city() {}
    }

   
}

